簡體   English   中英

在JQuery中使用通配符搜索HTML5數據屬性

[英]Searching HTML5 data attributes using wildcards in JQuery

我有以下使用HTML 5數據屬性的元素列表。

<div data-element="INFO-NAME"></div>
<div data-element="INFO-EMAIL"></div>
<div data-element="INFO-ADDRESS"></div>
<div data-element="INFO-ZIP"></div>

我想要做的是獲取包含的所有元素的列表

data-element="INFO-*"

我嘗試了$('[data-element="INFO-*"]')但這會返回一個空對象。 我該如何檢索此列表?

您可以使用

 $('[data-element^="INFO-"]')

這意味着查找具有屬性data-element任何元素,其值為以INFO-開頭

有關詳細信息,請參閱http://www.w3.org/TR/selectors/#attribute-substrings

使用^= ,這意味着«從»開始:

$('[data-element^="INFO-"]')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM