2011-07-11 46 views
0

我想在用户单击文档后隐藏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 
    } 
}); 

我的问题是我怎么能unbindhtml使得do something special停止射击annd整个事情里面的内容重新开始?

目前 - html.click();每次都会持续发射?

+0

什么整个事情意味着什么呢? – ShankarSangoli

+0

你为什么不直接绑定到div? HTML可能是危险的并且效率低下。 –

+0

这个问题是关于'unbind',而不是'die'。 – bluefoot

回答

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

您使用unbind方法:

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