Jquery hover отсоедините и снова привязать - PullRequest
1 голос
/ 05 октября 2011

Я сейчас использую этот бит 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, который делает именно то, что мне нужно, но в следующей функции,Что я положил, чтобы связать курсор (mouseenter mouseleave) обратно в функцию.Я попробовал несколько вариантов, но не вернусь к функции наведения у меня.

1 Ответ

2 голосов
/ 05 октября 2011
$(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");
});
...