Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$("div", $("body")).length
在 qUnit 文档中看到了类似的东西,我以前从未见过类似的东西。
第二个参数是如下语法中的上下文,
jQuery( selector [, context] ) selector: A string containing a selector expression context: A DOM Element, Document, or jQuery to use as context
jQuery( selector [, context] )
selector: A string containing a selector expression context: A DOM Element, Document, or jQuery to use as context
基本上定义如下,
默认情况下,选择器从文档根目录开始在 DOM 中执行搜索。但是,可以使用 $() 函数的可选第二个参数为搜索提供替代上下文。
http://api.jquery.com/jQuery/