gpt4 book ai didi

javascript - 用户选择选项后如何从选择标签获取数据att

转载 作者:行者123 更新时间:2023-12-01 00:22:06 25 4
gpt4 key购买 nike

HTML:

<div class="form-group ">
<select class="form-control input-sm col-xs-2 game-select" data-game="LuckyTuesday">
<option value="" disabled selected>Select Game </option>

<option id="1" data-name="Direct 1" data-minNumber="1" data-maxNumber="1">
Direct 1
</option>
<option id="2" data-name="Direct 2" data-minNumber="2" data-maxNumber="2">
Direct 2
</option>
</select>
</div>

JavaScript:

$('select').change(function () {
let gameType = $(this).find(':selected').attr('data-name');

//How to can I use "game-select" class to get "data-game" att?
});

最佳答案

您只需使用 data() jQuery 函数即可获取 data-game 的值:

$(this).data('game');

关于javascript - 用户选择选项后如何从选择标签获取数据att,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59331064/

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