【问题标题】:Removing event handlers of children删除孩子的事件处理程序
【发布时间】:2011-03-22 18:10:47
【问题描述】:

我正在尝试从所有 a 标记中取消绑定事件处理程序(单击),但不知何故它不起作用。你们知道为什么吗?

// Remove eventhandlers
    row.find('a').each(function(){
        $(this).unbind('click');
        alert($(this).attr("onClick"));
    });

它会一直输出当前的onClick函数。

谢谢

【问题讨论】:

    标签: jquery events event-handling unbind


    【解决方案1】:
    $('a').unbind('click');
    

    $('a').each(function() {
      return false;
    });
    

    【讨论】:

      【解决方案2】:

      jQuery 的.unbind() 仅删除由 jQuery 分配和维护的处理程序。您的内联处理程序不受影响。

      如果要删除内联属性,请使用removeAttr()

      row.find('a').each(function(){
          $(this).removeAttr('onClick');
          alert($(this).attr("onClick"));
      });
      

      http://api.jquery.com/removeattr/

      【讨论】:

        猜你喜欢
        • 2010-11-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-14
        相关资源
        最近更新 更多