【问题标题】:Pass multiple arguments to $.delegate将多个参数传递给 $.delegate
【发布时间】:2011-11-14 00:59:26
【问题描述】:

参数来自jQuery $(this) 并包含多个元素:)

试过

  $('#el').delegate($(this), 'click' ...

  $('#el').delegate($(this).each(), 'click' ...

没用..


(function($){
  $.fn.myfunction= function(){

    // here i need to somehow find .a, .b., .c etc... 
    $('#el').delegate($(this), 'click', function(event){

    });

  });
});

后来我这样称呼它:

  jQuery(document).ready(function($){
      $('.a, .b, .c').myfunction();
  });

所以我希望我的活动在所有新的 .a、.b、.c ...

【问题讨论】:

  • 这没有任何意义。你想做什么?
  • 我想在某些元素的点击事件上挂钩一个函数
  • 这仍然没有任何意义。在这种情况下,this 是什么?也许你应该展示一些 HTML 和/或上面代码周围的代码。
  • 我发布了更多代码,抱歉我不知道如何更好地解释这个:(

标签: jquery jquery-selectors delegates


【解决方案1】:

你应该添加一个普通的处理程序:

$(this).bind('click', ...);

你也可以写$(this).click(...)

.delegate 允许您处理在匹配选择器的元素的子元素中发生的所有事件。

【讨论】:

    【解决方案2】:

    根据您的代码,您将需要$("xxxx").bind('click',function(e) {...});$("xxx").live('click', function(e) {...});

    如果您使用的是 jquery v1.7,$.on() 是要使用的函数,而 $.off() 会反转它。

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 1970-01-01
      • 2016-07-18
      • 2013-01-07
      • 2011-10-10
      • 2013-09-15
      • 2010-10-09
      • 2012-09-05
      • 2017-06-14
      相关资源
      最近更新 更多