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-game
jQuery函数即可获得data()
的值:
$(this).data('game');