【发布时间】:2021-05-31 17:00:50
【问题描述】:
我有 2 个单选按钮,每个按钮分别为 Yes 和 No 以及 1 个文本框。如果我选中 No 按钮,输入文本框将打开。如果选中是,文本框将被禁用。
此代码运行良好,但如果用户选中“是”,我想删除输入到文本框的内容
function ismcstopu() {
var chkNo = document.getElementById("radio2_ismcstop");
var mcnostopreason = document.getElementById("mcnostopreason");
mcnostopreason.disabled = chkNo.checked ? false : true;
if (!mcnostopreason.disabled) {
mcnostopreason.focus();
} else {
mcnostopreason.val('');
}
}
<input type="radio" class="form-check-input" id="radio1_ismcstop" name="ismcstop" onclick="ismcstopu()" value="Yes">Yes
<input type="radio" class="form-check-input" id="radio2_ismcstop" name="ismcstop" onclick="ismcstopu()" value="No">No
<label for="mcnostopreason">If No, Reason:</label>
<input class="inputstyle-100" type="text" id="mcnostopreason" name="mcnostopreason" value="" disabled>
【问题讨论】:
标签: javascript php html jquery laravel