gpt4 book ai didi

jquery - $(first, secondary) 中第二个参数的目的是什么

转载 作者:行者123 更新时间:2023-12-01 02:21:55 25 4
gpt4 key购买 nike

Possible Duplicate:
What does the second argument to $() mean?

有一段时间我使用 jQuery,时不时地我会看到这个:

$(argument1, argument2).doSomething();

使用第二个参数进行过滤的文档在哪里?

编辑:

我正在谈论这种使用方式:

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();
}
});

注意:

$("*",elem)

我不是在说

$("a,b,span")

过滤方式。我现在很好。

最佳答案

这是 jQuery() documentation 中的第一个定义:

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

再往下:

Selector Context

By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the $() function.

但是,在内部它只是调用 .find您经常会发现人们建议使用 .find 而不是传递第二个参数。

因此,您的示例相当于 $(argument2).find(argument1).doSomething();

关于jquery - $(first, secondary) 中第二个参数的目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14605992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com