Jquery 选中复选框时,将其设置为禁用或只读
当用户选中复选框时,是否可以设置只读或禁用属性Jquery 选中复选框时,将其设置为禁用或只读,jquery,Jquery,当用户选中复选框时,是否可以设置只读或禁用属性 <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="checkbox"> <label> <input type="checkbox" name="checkbox" id="checkbox"> Rememb
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox" name="checkbox" id="checkbox"> Remember me
</label>
</div>
</div>
这样试试。但正如我在评论中所说,一旦你禁用了这个复选框,你就没有办法再启用它,也许你需要改变你的方法
使用选择器ID
并使用propdisabled
禁用复选框notreadonly
$(document).ready(function() {
$("#checkbox").change(function() {
if ($(this).is(':checked')) {//check if checkbox is checked
$(this).prop('disabled', true)
}
});
});
是的,您可能尝试过什么?如果禁用,您将如何启用?这样您就无法撤消禁用复选框。只是想一想我已经更新了我的post@LucasFrugier我看到了快乐coding@guradio您可以通过另一个事件(如单击按钮或选择另一个DOM元素)再次启用它@LelioFaieta是的,我的意思是他不能在取消选中同一复选框时启用它。对不起,那件事我不清楚。谢谢你,我没想到你会来
$(document).ready(function() {
$("#checkbox").change(function() {
if ($(this).is(':checked')) {//check if checkbox is checked
$(this).prop('disabled', true)
}
});
});