jquery - 将多个参数传递给 $.delegate

标签 jquery jquery-selectors delegates

参数来自 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).bind('click', ...);

您也可以只写$(this).click(...)

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

关于jquery - 将多个参数传递给 $.delegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8116169/

相关文章:

javascript - 在 ios 8 应用程序扩展 javascript 文件中使用 jQuery

javascript - 使用 javascript(或 jQuery)选择和操作 CSS 伪元素,例如::before 和::after

jquery - 使用 jquery 插件选择表单中所有输入的最佳方法是什么

ios - UITableView 委托(delegate)

c# - 模拟事件处理器

来自标签的 JavaScript 警报值

javascript - jQuery 到纯 JavaScript

javascript - 日期范围选择器(用于 Bootstrap 的 JavaScript 组件)在特定日期选择了错误的日期

jquery - 按名称选择 div 中的输入

ios - 如何将数据传递到 UINavigationController 堆栈上的第 n 个 View Controller ?