后代选择器和jQuery的选择器有什么区别
问题说明
来自文档:
后代选择器
描述:选择作为给定祖先后代的所有元素。
Description: Selects all elements that are descendants of a given ancestor.
元素的后代可以是该元素的子元素,孙子元素,曾孙元素等等。
A descendant of an element could be a child, grandchild, great-grandchild, and so on, of that element.
:has
描述:选择包含至少一个与指定选择器匹配的元素的元素。
Description: Selects elements which contain at least one element that matches the specified selector.
表达式 $('div:has(p)')
匹配< div>
如果< p>
存在于其后代中的任何地方,而不仅仅是直接的孩子。
The expression $('div:has(p)')
matches a <div>
if a <p>
exists anywhere among its descendants, not just as a direct child.
即使在阅读了解释之后,差异也不明确。有人可以帮我理解吗?
Even after reading the explanation, the difference is not clear to me. Can someone help me understand?
正确答案
div p
中的后代选择器选择 div
的 p
后代。
The descendant selector in div p
selects the p
descendants of the div
.
:
选择 div中的has()
选择器:has(p) div
如果它包含任何 p
元素。
The :has()
selector in div:has(p)
selects the div
if it contains any p
elements.
大胆的部分是您需要知道的。其余部分可以被视为条件选择这些类型的哪些元素。
The bold parts are all you need to know. The rest can be seen as mere conditions as to which elements of those types are selected.
在CSS选择器术语中,键选择器是最右侧的外部简单选择器。 jQuery(或浏览器的CSS解析器)获取的元素类型是键选择器中的元素。
In CSS selector terms, the key selector is the right-most outer simple selector. The kind of elements that get picked up by jQuery (or by a browser's CSS parser) is the one in the key selector.
在第一个选择器中,键是 p
,因为它是最右边的一个,发生在后代组合子(空间)之后。这意味着将返回 p
元素的集合。
In the first selector, the key is p
, because it's the right-most one, occurring after the descendant combinator (the space). This means a collection of p
elements will be returned.
在的情况下: has()
,这是一个伪类, p
是一个内部简单选择器,它是 <$>的一部分c $ c>:has()伪类,不是整个外部选择器的一部分。因此,该选择器中的键是 div
,而不是 p
。这意味着将返回 div
元素的集合,而不是第一个选择器中的 p
元素。
In the case of :has()
, which is a pseudo-class, the p
is an "inner" simple selector that is part of the :has()
pseudo-class, not part of the entire "outer" selector. The key in that selector is therefore div
, not p
. This means a collection of div
elements will be returned, rather than p
elements in the first selector.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcckjkj
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20