简体   繁体   English

Javascript、jQuery 元素选择器

[英]Javascript, jQuery element selectors

I can't understand what this selector selects actually:我无法理解这个选择器实际上选择了什么:

var x=$("a[href*='y']")

Could you guys explain it me in plain English.你们能不能用简单的英语给我解释一下。

Thanx in advance Dhiaa提前感谢 Dhiaa

*= means contains, so in this case it is selecting all anchor ( a ) tags that contain y *=表示包含,所以在这种情况下它选择所有包含y锚 ( a ) 标签

See documentation on jquery selectors here.此处查看有关 jquery 选择器的文档

a[href*='y'] matches any elements that: a[href*='y']匹配符合以下条件的任何元素:

  1. Are a elements, anda元素
  2. Have an href attribute that contains y ( [attr*=...] is an attribute 'contains' substring selector; spec , jQuery )有一个包含yhref属性( [attr*=...]是一个属性“包含”子字符串选择器;规范jQuery

This selector selects an with attribute, contains href='y'.这个选择器选择一个 with 属性,包含 href='y'。 That means that you select some link () which leads (href) to y这意味着您选择了一些将 (href) 引向 y 的链接 ()

Read more about jq attributes here https://api.jquery.com/category/selectors/attribute-selectors/在此处阅读有关 jq 属性的更多信息https://api.jquery.com/category/selectors/attribute-selectors/

它选择每个 href 属性值包含“y”的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM