为什么jQuery在关键字之前放置冒号? [英] Why does jQuery put the colon before the keyword?

查看:118
本文介绍了为什么jQuery在关键字之前放置冒号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我们有像 is(:visible) $(div)。(:first)



为什么冒号在前面,它的目的是什么?

解决方案

它们是 jQuery Selector Extensions 给你布尔输出,它与CSS规范没有任何关系。这是完全无效的:

  $(div)。(:first)



我们使用:

$ 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 DOM querySelectorAll() 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆