[英]Disabling the checkbox when the checkbox is checked
I have this for my checkbox, 我有这个用于我的复选框,
$('.cuttingCheckbox').change(function() {
if (this.checked) {
alert('checked');
} else {
alert('unchecked');
}
});
I want to disabled it right after the user check the checkbox. 我想在用户选中复选框后立即禁用它。 Please help me on how to do this.
请帮助我。 I know this is very simple but im very new on this stuff.
我知道这很简单,但是我在这方面很新。
Just set the disabled
attribute to true
when you detect that the checkbox is in a checked state, IE: 当您检测到复选框处于选中状态IE时,只需将
disabled
属性设置为true
:
$('.cuttingCheckbox').change(function() {
if (this.checked) {
alert('checked');
this.disabled = true;
} else {
alert('unchecked');
}
});
I would also recommend thinking through why you want to disable it. 我还建议您仔细考虑为什么要禁用它。 Disabled form element values are not sent to the server.
禁用的表单元素值不会发送到服务器。
$('.cuttingCheckbox').change(function() {
if (this.checked) {
document.getElementById("cuttingCheckbox").disabled= true
} else {
document.getElementById("cuttingCheckbox").disabled = false
}
});
Hope this might help. 希望这会有所帮助。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.