繁体   English   中英

使用* =的jQuery属性选择器

[英]jQuery attribute selector using *=

查看以下jQuery选择器: $('img[alt*="Robin"]') 它选择什么?

我了解这行代码...除了*部分。 *是什么意思?

这意味着alt属性需要包含Robin (但不一定相等)。 例如,

<img alt="whoisRobin"/>
<img alt="Robin"/>
<img alt="Robinaa"/>

将被选中,但以下内容不会:

<img alt="Robi"/>

jQuery文档中的更多信息

*表示包含特定字符串的值。

任何具有alt属性的图片都包含“ Robin”

它是包含选择器的属性。

参见http://api.jquery.com/attribute-contains-selector/

Selects elements that have the specified attribute with a value containing the a given substring

它会

查找带有包含Robinalt属性的所有输入,并使用一些文本设置值。

属性包含选择器

选择具有指定属性且其值包含给定子字符串的元素

对于EGS,

<img alt="Robin-news" src='...'/>
<img alt="xyzRobin" src='...'/>
<img alt="letterRobin2" src='...'/>
<img alt="newone" src='...'/>

脚本

$('img[alt*="Robin"]');// outputs First 3 image objects

*与属性值中的子字符串匹配。 因此,将选择具有alt属性值的包含子字符串“ Robin”的图像。

http://api.jquery.com/attribute-contains-selector/

暂无
暂无

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

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