[英]How to get price instead of data-price/value in Javascript?
標題怎么說...我該如何獲取price =“”。
在下面的HTML中,這是在Magento中的,我正在嘗試通過定義自定義Javascript來覆蓋。 這就是為什么我沒有將其發布到Magento Stack Overflow。 select標簽內的選項如下所示:
<option id="sample" value="46" price="2">50 x 46cm +$2.00</option>
我該如何把握價格?
$('select').on('change', function() {
var a = $(this).data(price);
alert( a );
});
您需要來自選定子項的屬性
$('select').on('change', function() {
var a = $(this).find(':selected').attr('price');
alert( a );
});
假定<select>
未被設置為multiple
。 使用html5 data-
屬性也更常見,但應該可以正常工作
$('select').on('change', function() {
var selected = $( "select option:selected " ).attr('price');
console.log(selected);
});
或者如果你有
$('.sample_list').on('change', function() {
var selected = $( ".sample_list option:selected " ).attr('price');
console.log(selected);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.