2011-10-05 37 views
1

我目前正在使用這一點的jquery。jquery懸停取消綁定和再次綁定

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

在第一個功能我已經添加了mouseenter的.unbind,這不正是我需要它,但在接下來的功能,不要我把什麼懸停(的mouseenter鼠標離開)綁定回功能。我試過幾個選項,但不會回到我的懸停功能。

回答

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

謝謝!試用過,並且完美無缺! – c0rdii

+0

哈哈!真棒。擊中複選框並給我信用;) – DefyGravity

相關問題