$(':radio, :checkbox', this) 为什么 $ 选择器中有 2 个参数?在 jquery 插件中

$(':radio, :checkbox', this) why 2 arg in a $ selector? in jquery plugin

  $(':radio, :checkbox', this).wrap('<div style="margin: 1px"/>');
  $(this).buttonset();
  $('label:first', this).removeClass('ui-corner-left').addClass('ui-corner-top');
  $('label:last', this).removeClass('ui-corner-right').addClass('ui-corner-bottom');

如上,我能理解为什么一个$?里面有2个arg了? 我用谷歌搜索但仍然找不到相关讨论

在此select或:

$(':radio, :checkbox', this)

this 是包含 radio and checkbox.

的包装器

考虑这个例子:

$('form').submit(function(){
   if(!$(':checkbox, :radio', this).prop('checked')){
      alert('please select checkbox and radio.');
   }
});

所以在上面的例子中 $(':checkbox, :radio', this) 这个 select 或者你可以看到它在 $('form') 的上下文中所以这里 this 实际上是 form并且您正在尝试 select 它的特定子项。

这一行其实你也可以这样写:

$(this).find(':checkbox, :radio')