【发布时间】:2018-07-08 11:30:14
【问题描述】:
这是很基本的,但我无法理解。
在捐赠表格上,人们可以选择预设的金额选项或“其他”。如果他们选择“其他”,即使选择了预设,也必须激活“其他”单选按钮。
HTML:
<label>
<input type="radio" name="x_ccPayment" class="required" title="*"
value="120" data-payment="once" />
$120</label>
<label>
<input type="radio" name="x_ccPayment" class="required" title="*"
value="50" data-payment="once" />
$50</label>
<label>
<input type="radio" name="x_ccPayment" class="required" title="*"
value="-99" data-payment="once" />
Other:</label>
<input type="text" name="x_ccPayment_other" id="other_once" style="width: 100px;" value="" onKeyUp="checkNumericInput(this)" data-payment="once" class="form-control" />
查询:
$("#other_once").keyup(function(){
var other_once = $("#other_once").val();
if (other_once !=='') {
$("input[name=x_ccPayment]").removeAttr('checked'); // deselect other options
$("input[name=x_ccPayment][data-payment=once][value=-99]").attr('checked','checked'); /auto-select the 'other' radio
}
});
当我查看开发工具时,我看到收音机是 checked 正确,但屏幕上没有显示。
【问题讨论】:
-
不要使用
.attr修改属性。
标签: jquery