此代码运行良好,但缺少一些我需要的东西。
基本上,如果输入有一个 checked="checked"
属性,它应该使其他两个元素保持禁用状态。如果未选中,则元素已启用。
这是我在 jsFiddle 上的代码:http://jsfiddle.net/arunpjohny/gMgm7/1/
这就是我的输入
<input class="test_priv1" type="checkbox" name="custom" id="custom" checked="checked" onclick="" />
我想这会被翻译成: 如果我的输入得到检查,请禁用其他两个元素。如果我的输入有 checked="checked"然后禁用我的其他两个元素。如果我的输入未选中,则启用这两个元素。
最佳答案
成功了:
$(document).ready(function() {
if ($('.test_priv1').is(':checked')){
$('.test_priv2, .test_priv3').prop('disabled',true);
}
$('.test_priv1').change(function () {
if(this.checked){
$('.test_priv2, .test_priv3').prop('disabled',true);
}else{
$('.test_priv2, .test_priv3').removeAttr('disabled');
}
});
});
关于javascript - Bootstrap : how to check if an elment is checked and set it to disable if checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24070312/