如何阻止Live Bind()

时间:2011-07-11 17:33:54

标签: jquery bind live unbind

我试图在用户点击文档后隐藏div

<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
    }
});

我的问题是我如何unbind html以便do something special内的内容停止解雇并重新开始整个事情?

目前 - html.click();每次都在开火?

2 个答案:

答案 0 :(得分:0)

您使用unbind方法:

$("html").unbind("click");

答案 1 :(得分: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');
        }
    });