【发布时间】:2016-01-12 21:37:59
【问题描述】:
您好,当用户在我的输入文本框中输入 8 位数字时,我试图让我的复选框被选中。现在我可以在用户输入时选中复选框,但我是新用户,无法弄清楚。感谢您的帮助。
<input id="thecheckbox" type="checkbox">
<input id="theinput" type="text">
$("#theinput").keyup(function () {
if ($(this).val() == "") {
$("#thecheckbox").prop("checked", false);
} else {
$("#thecheckbox").prop("checked", true);
}
});
$("#thecheckbox").change(function () {
if (!$(this).is(':checked')) {
$("#theinput").val("");
}
});
【问题讨论】:
标签: javascript html checkbox input