Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于点击对象父容器的问题 点击某一天时,tbody的父亲为空 #62

Open
zhishaofei3 opened this issue Oct 15, 2014 · 2 comments

Comments

@zhishaofei3
Copy link

需求是页面里有一个浮窗,浮窗里是日历的input,浮窗需要点的不是它的时候隐藏。
这时候 我在浮窗展示的时候,会增加以下事件侦听:

$(document).on("click", clkDocument);
function clkDocument(e){
        var drag = $doubleChoose,
            dragel = $doubleChoose[0],
            target = e.target;

        console.log($(target).parents(".ui-calendar").length);

        while(target){
            if(target.tagName == "BODY"){
                break;
            }
            console.log(target);
            console.log(target.parentNode);
            target = target.parentNode;
        }
        return;
//      if (dragel !== target && !$.contains(dragel, target)) {
//          $(document).off("click", clkDocument);
//          drag.hide();
//      }
    }

calendar click
我用while遍历target的parent(),发现如果点的是绿色区域,就会遍历到body,
但是如果点击红色区域,就会停止在tbody,因为显示tbody的父亲为null,
请问这是什么原因?貌似跟calendar的js有关。

calendar log

同样,我在用jQuery输出$(target).parents(".ui-calendar").length和使用jQuery的$.contains()来判定的时候,也是这个现象。

$(target).parents(".ui-calendar").length点绿色部分的时候就输出1,红色部分就输出0。
$.contains($(".ui-calendar")[0], target); 输出false

这样使我没法判断点的是日历,我判断不了当前点击的是日历,那么装input的浮窗就会被隐藏。。。。
请教这是什么原因?我猜想的是跟重写了下面的日期有关?

下面是我目前比较垃圾的解决办法:

    function clkDocument(e){
        var drag = $doubleChoose,
            dragel = $doubleChoose[0],
            target = e.target;

        if ($(target).parents(".ui-calendar").length != 0) {//点击日历上半部分
            return;
        }
        if(target.className.indexOf("current-month") != -1){//点击日历下半部分
            return;
        }

        if (dragel !== target && !$.contains(dragel, target)) {
            $(document).off("click", clkDocument);
            drag.hide();
        }
    }
@afc163
Copy link
Member

afc163 commented Nov 4, 2014

没明白你的具体需求是什么?

是否是输入框和日历始终展示?

@zhishaofei3
Copy link
Author

已经解决了,input在一个浮窗里,点击input的时候会打开日历,点击页面其他地方的时候关闭日历,我现在希望点击页面其他地方的时候,关闭日历和浮层,我给document增加的click事件,所以我需要知道点击的是日历还是外面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants