簡體   English   中英

如何在 jquery 或 javascript 中計算標簽 a 中的數據 ID?

[英]How to count data-id in tag a in jquery or just javascript?

在一個標簽中計算數據 ID a如何在數據 ID 中或通過 javascript 計算我的屬性 ID?

編輯

假設您正在嘗試解析所有 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.

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