0

我试图div在用户单击文档后隐藏 a 。

<div class="active">
   <a class="agree" href="javascript:;">I Agree</a>
   <a class="disagree" href="javascript:;">Disagree</a>
</div>

使用以下解决方案 -

var mouseOverActiveElement = false;

$('.active').live('mouseenter', function(){
    mouseOverActiveElement = true; 
}).live('mouseleave', function(){ 
    mouseOverActiveElement = false; 
});
$("html").click(function(){ 
    if (!mouseOverActiveElement) {
        //Do something special
    }
});

我的问题是我怎样才能unbindhtml里面的内容do something special停止发射,整个事情又开始了?

此刻——html.click();每次都在不停地开火?

4

2 回答 2

0

您使用unbind方法:

$("html").unbind("click");
于 2011-07-11T17:37:44.713 回答
0

试试这个

    var mouseOverActiveElement = false;

    $('.active').live('mouseenter', function(){
        mouseOverActiveElement = true; 
    }).live('mouseleave', function(){ 
        mouseOverActiveElement = false; 
    });
    $("html").click(function(){ 
        if (!mouseOverActiveElement) {
            //Do something special
            mouseOverActiveElement = false;

//If you want to unbind html click event then use $("html").unbind('click');
        }
    });
于 2011-07-11T17:42:05.210 回答