【发布时间】:2016-01-21 05:40:45
【问题描述】:
我有一个网络表单,它允许用户使用预定义的单选按钮捐款,并为他们分配一个值(所有不同的数字)。我还有一个选择您自己的金额文本字段,他们可以在他们希望捐赠的自定义金额中写入。如果用户选择了预定义的选项,我想清除自定义文本字段。
到目前为止,我已经创建了这个:
HTML:
<input type="radio" name="am_payment" value="3" checked="checked"> <strong>64</strong>
<input type="radio" name="am_payment" value="11" checked="checked"> <strong>100</strong>
<input type="radio" name="am_payment" value="32" checked="checked"> <strong>250</strong>
<input type="radio" value="" name="am_payment"><label>Other</label>
<input type="text" name="CP_otheramount" value="" id="theamount" disabled="disabled"/>
JAVASCRIPT:
$('input[name="am_payment"]').on('click', function() {
if ($(this).val() === '') {
$('#theamount').removeProp("disabled");
}
else {
$('#theamount').prop("disabled", "disabled");
$('input[name="CP_otheramount"]').val("");
}
});
但基于value === true 为value="" 似乎并不正确。
有什么办法可以改善吗?
谢谢
【问题讨论】:
-
启用禁用字段使用
$('#theamount').prop("disabled", true/false); -
Go through the linkDemo is here please check it
标签: javascript jquery html textbox