我只是看着jQueryUI按钮插件并注意到了这一点
$("button, input:submit, a", ".demo").button();
Run Code Online (Sandbox Code Playgroud)
我从来没有见过这样的东西.这在一个jQuery选择器中是多次选择吗?
CMS*_*CMS 165
第二个参数(".demo"在您的示例中)是上下文,基本上您的选择器被限制为仅匹配确定的上下文的后代:
$(expr, context)
Run Code Online (Sandbox Code Playgroud)
只是等效使用find方法:
$(context).find(expr)
Run Code Online (Sandbox Code Playgroud)
看一下jQuery函数的文档:
选择器上下文
默认情况下,选择器在从文档根开始的DOM内执行搜索.但是,通过使用
$()函数的可选第二个参数,可以为搜索提供备用上下文.例如,如果在回调函数中我们希望搜索元素,我们可以限制该搜索:
$('div.foo').click(function() {
$('span', this).addClass('bar');
// it will find span elements that are
// descendants of the clicked element (this)
});
Run Code Online (Sandbox Code Playgroud)
另请注意,您发布的选择器"button, input:submit, a"称为多选择器,您可以指定任意数量的选择器组合成单个结果,只需用逗号分隔即可.