我在選項標簽中有自定義屬性的選擇型別。當我能夠獲得 val,但無法獲得自定義屬性中的值時。
這是 Jsfiddle
JSFIDDLE
<script>
jQuery(document).on('change','.selectedItem',function() {
var selectedValue = jQuery(this).val();
alert(selectedValue);
alert(jQuery(this).attr("id"));
var product_id = jQuery(this).attr('rel-product-id');
alert(product_id);
var product_name= jQuery(this).attr("rel-product-name");
alert(product_name);
});
</script>
uj5u.com熱心網友回復:
所以問題是你試圖從它select本身獲取屬性的值。你想要做的是從選擇讓他們option的的select使用option:selected。像這樣:
alert(jQuery('option:selected', this).attr('id'));
alert(jQuery('option:selected', this).attr('rel-product-id'));
alert(jQuery('option:selected', this).attr('rel-product-name'));
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/396873.html
標籤:javascript php html 查询
上一篇:PHP-從陣列中獲取資訊
