[英]How to count data-id in tag a in jquery or just javascript?
假設您正在嘗試解析所有 a 元素並查找以某個字符串開頭的特定屬性:
$(function() {
$("a").each(function() {
$.each(this.attributes,function(i,a){
if(a.name.match("^data-nilai")){
console.log(a.value)
}
})
})
})
據我所知,沒有用於搜索模糊屬性名稱的 JQuery 選擇器。 只有屬性值。
<html> <head> <script src="http://code.jquery.com/jquery-3.3.1.min.js"></script> </head> <body> <a href="#" data-nilai1="sadadfasdf" data-nilai2="asdfasdfasdf" data-nilai3="asdfasdf"></a> <script> $(function() { $("a").each(function() { $.each(this.attributes,function(i,a){ if(a.name.match("^data-nilai")){ console.log(a.value); } }) }) }) </script> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.