Hi Everyone onchange我想从下拉选项
中捕获所选的数据价格<select class="tmcp-field hotel support-layer-thickness tm-epo-field tmcp-select tm-valid" name="tmcp_select_10" data-price="" data-rules="" data-original-rules="" id="tmcp_select_44" tabindex="44" aria-invalid="false">
<option value="Select Thickness_0" class="tc-multiple-option tc-select-option" data-imagep="" data-price="" data-tm-tooltip-html="" >Select Thickness</option>
<option value="4_1" class="tc-multiple-option tc-select-option" data-imagep="" data-price="8000" data-tm-tooltip-html="" >4</option>
<option value="5_2" class="tc-multiple-option tc-select-option" data-imagep="" data-price="10000" data-tm-tooltip-html="" >5</option>
<option value="6_3" class="tc-multiple-option tc-select-option" data-imagep="" data-price="12000" data-tm-tooltip-html="" >6</option>
</select>
如何获取数据价格值
谢谢
答案 0 :(得分:3)
jQuery.data
用于与指定元素相关联的get/set
数据option:selected
选择器获取selected
选项
$('#tmcp_select_44').on('change', function() {
var option = $(this).find('option:selected');
console.log(option.data('price'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<select class="tmcp-field hotel support-layer-thickness tm-epo-field tmcp-select tm-valid" name="tmcp_select_10" data-price="" data-rules="" data-original-rules="" id="tmcp_select_44" tabindex="44" aria-invalid="false">
<option value="Select Thickness_0" class="tc-multiple-option tc-select-option" data-imagep="" data-price="" data-tm-tooltip-html="">Select Thickness</option>
<option value="4_1" class="tc-multiple-option tc-select-option" data-imagep="" data-price="8000" data-tm-tooltip-html="">4</option>
<option value="5_2" class="tc-multiple-option tc-select-option" data-imagep="" data-price="10000" data-tm-tooltip-html="">5</option>
<option value="6_3" class="tc-multiple-option tc-select-option" data-imagep="" data-price="12000" data-tm-tooltip-html="">6</option>
</select>