可能重复:
$()的第二个参数是什么意思?
有一段时间我使用jQuery,有时我会看到:
$(argument1, argument2).doSomething();
Run Code Online (Sandbox Code Playgroud)
使用第二个参数进行过滤的文档在哪里?
编辑:
我在谈论这种使用方式:
var t=0; // the height of the highest element (after the function runs)
var t_elem; // the highest element (after the function runs)
$("*",elem).each(function () {
$this = $(this);
if ( $this.outerHeight() > t ) {
t_elem=this;
t=$this.outerHeight();
}
});
Run Code Online (Sandbox Code Playgroud)
注意:
$("*",elem)
Run Code Online (Sandbox Code Playgroud)
我不是在谈论
$("a,b,span")
Run Code Online (Sandbox Code Playgroud)
过滤方式.我现在很好.
这是jQuery()文档中的第一个定义:
jQuery( selector [, context ] )
selector
Type: selector
A string containing a selector expression
context
Type: Element, jQuery
A DOM Element, Document, or jQuery to use as context
Run Code Online (Sandbox Code Playgroud)
进一步向下:
选择器上下文
默认情况下,选择器在从文档根开始的DOM内执行搜索.但是,通过使用
$()函数的可选第二个参数,可以为搜索提供备用上下文.
但是,在内部它只是调用.find,你经常会发现人们建议使用.find过度传递第二个参数.
所以,你的例子相当于 $(argument2).find(argument1).doSomething();
| 归档时间: |
|
| 查看次数: |
896 次 |
| 最近记录: |