【问题标题】:Jquery hover unbind and binding againJquery悬停解除绑定并再次绑定
【发布时间】:2011-10-05 00:35:39
【问题描述】:

我目前正在使用这个 Jquery。

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

在第一个函数中,我添加了一个 .unbind 的 mouseenter,这正是我需要的,但在下一个函数中,我应该将悬停 (mouseenter mouseleave) 绑定回函数中。我尝试了一些选项,但不会回到我拥有的悬停功能。

【问题讨论】:

    标签: jquery hover bind mouseenter mouseleave


    【解决方案1】:
    $(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");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-21
      • 1970-01-01
      • 2012-03-02
      相关资源
      最近更新 更多