gpt4 book ai didi

jquery - jquery中的数据属性

转载 作者:可可西里 更新时间:2023-11-01 13:08:30 25 4
gpt4 key购买 nike

这是我的html代码

<select class="data">
<option value="This is my test code" data-id='123'/>
</select>

现在我想访问 jquery 中的数据属性这是我的 jquery 代码

$( ".data" ).change(function() {
var Id = $(this).data("id")
alert("id: "+Id);
});

但是当我尝试这个时,它给出了一个未定义的值。请帮助我。

最佳答案

使用这个

$( ".data" ).change(function() {
var Id = $(this).find('option:selected').data("id")
alert("id: "+Id);
});

关于jquery - jquery中的数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28831196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com