我试图在触发单选按钮时更改按钮值。
<fieldset id="product-color">
<input type="radio" id="red" name="color" value="Red">
<label for="red">Red</label><br>
<input type="radio" id="blue" name="color" value="Blue">
<label for="blue">Blue</label><br>
</fieldset>
<button
id="order-button"
data-item-id="1"
data-item-name="Shirt"
data-item-price="20"
data-item-custom2-name="Color"
data-item-custom2-options="Red|Blue">
Add Item
</button>
通过使用这个小脚本:
$('#product-color').change(function() {
$('#order-button').data('item-custom2-value', $(this).val());
});
对于select输入字段,它工作得很好,但对字段集却不是这样。有什么不同吗?
发布于 2016-12-16 01:40:44
您需要更改单选按钮的事件,因为事件是在单选按钮上触发的,而不是字段集:
$('#product-color input').change(function() {
$('#order-button').data('item-custom2-value', $(this).val());
});
https://stackoverflow.com/questions/41181263
复制相似问题