[英]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.