为什么jQuery在关键字之前放置冒号? [英] Why does jQuery put the colon before the keyword?
问题描述
例如,我们有像 is(:visible)
或 $(div)。(:first)
为什么冒号在前面,它的目的是什么?
它们是 jQuery Selector Extensions 给你布尔输出,它与CSS规范没有任何关系。这是完全无效的:
$(div)。(:first)
$ c
我们使用:
$ p $ $($ div:first)
在jQuery中,不是另一个。对于布尔输出,我们使用:
if($(div)。is(:first))
if($(div)。is(:visible))
if($(div)。(:empty))
以上是几个例子。它也记录在那里:
lockquote
因为:visible
是一个 jQuery扩展和不是CSS规范的一部分,使用:visible的查询无法利用本机DOM提供的性能提升 querySelectorAll()
方法。为了在使用时达到最佳性能:选择元素可见,首先使用纯CSS选择器选择元素,然后使用 .filter(:visible)
。
For example, we have like is(":visible")
or $("div").(":first")
Why is the colon in the front and what is it's purpose?
They are jQuery Selector Extensions which give you boolean output, and it has nothing to do with CSS Specifications. This is totally invalid:
$("div").(":first")
We use:
$("div:first")
in jQuery, not the other one. For the boolean output, we use:
if ($("div").is(":first"))
if ($("div").is(":visible"))
if ($("div").is(":empty"))
The above are few examples. It is also documented there:
Because
:visible
is a jQuery extension and not part of the CSS specification, queries using :visible cannot take advantage of the performance boost provided by the native DOMquerySelectorAll()
method. To achieve the best performance when using :visible to select elements, first select the elements using a pure CSS selector, then use.filter(":visible")
.
这篇关于为什么jQuery在关键字之前放置冒号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!