Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery获取锚定标记的数据值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jquery获取锚定标记的数据值

Javascript 使用jquery获取锚定标记的数据值,javascript,jquery,html,Javascript,Jquery,Html,谢谢您可以使用: 在指定的数据存储中返回 jQuery集合,由数据(名称、值)或HTML5数据集设置-* 属性 还请注意,您的锚定的名称是选项卡而不是选项卡,因此您需要使用: var a = $(this).data("index"); 使用.data(): 在jquery中使用.attr() $(this).data('index') $("a[name=tabs]").on("click", function () { var a = $(this).att

谢谢

您可以使用

在指定的数据存储中返回 jQuery集合,由数据(名称、值)或HTML5数据集设置-* 属性

还请注意,您的锚定的
名称是
选项卡
而不是
选项卡
,因此您需要使用:

var a = $(this).data("index"); 

使用
.data()

在jquery中使用
.attr()

$(this).data('index')
 $("a[name=tabs]").on("click", function () { 
            var a = $(this).attr("data-index"); 
            alert(a); 
        });
或者在jquery中使用
.data()

$(this).data('index')
 $("a[name=tabs]").on("click", function () { 
            var a = $(this).attr("data-index"); 
            alert(a); 
        });
您可以使用:

 $("a[name=tabs]").on("click", function () { 
            var a = $(this).data("index"); 
            alert(a); 
        });
我肯定会看看这个,因为它显示了HTML5中的变化,以及我们如何使用jQuery有效地从HTML5数据属性中获取信息。

$(this.data('index')
 $("a[name=tabs]").on("click", function () { 
            var a = $(this).data("index"); 
            alert(a); 
        });
$("a[name=tabs]").on("click", function () { 
    var a = $(this).data('index'); 
    alert(a); 
});