Jquery再次将unbind和绑定挂起

时间:2011-10-05 00:35:39

标签: jquery hover bind mouseenter mouseleave

我目前正在使用这个Jquery。

$(".option5").toggle(
function () {
    $(this).addClass("red"),
    $("#check5").attr('checked',true),
    $(".option5").unbind('mouseenter');
  },
function () {
    $(this).removeClass("red"),
    $("#check5").attr('checked',false),
});

在第一个函数中,我添加了一个.unbind of mouseenter,它完全符合我的需要,但是在下一个函数中,我将把hover(mouseenter mouseleave)绑定回函数。我尝试了一些选项,但不会回到我的悬停功能。

1 个答案:

答案 0 :(得分:2)

$(document).ready(function(){

$(".option5").bind("refreshMouseEnter", function(event){
  $(this).mouseenter(function(event){
    //do your work
  });
}).bind("refreshMouseLeave", function(event){
  $(this).mouseleave(function(event){
   //do your work
  });
}).toggle(
function () {
    $(this).addClass("red"),
    $("#check5").attr('checked',true),
    $(".option5").unbind('mouseenter');
  },
function () {
    $(this).removeClass("red"),
    $("#check5").attr('checked',false),
///be very sure you want this selector!!! i just copied from above...
    $(".option5").trigger('refreshMouseEnter');
}).trigger("refreshMouseEnter").trigger("refreshMouseLeave");
});
相关问题