【发布时间】:2016-12-16 09:38:31
【问题描述】:
我正在尝试在触发单选按钮时更改按钮值。
<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-input-field 可以很好地工作,但不能使用 fieldset。有什么区别吗?
【问题讨论】:
-
OP 有点不清楚您要更改按钮单击或单选按钮更改时的值的事件。您还想将哪个值分配为字段集的数据值?
标签: javascript jquery forms onchange fieldset