Javascript 检查一组复选框是否在引导中选中复选框。

Javascript 检查一组复选框是否在引导中选中复选框。,javascript,jquery,html,twitter-bootstrap,twitter-bootstrap-3,Javascript,Jquery,Html,Twitter Bootstrap,Twitter Bootstrap 3,您好,我在Bootstrap3中执行此操作时遇到问题。我已经在JSFIDLE中使用了这段代码,但它不能在引导程序中使用 这是 HTML <div class="col-md-3 span6 privilege-container-b"> <label class="checkbox"> <input type="checkbox" name="mypriv" value="test_priv1" class="test_priv1">Checkbox

您好,我在Bootstrap3中执行此操作时遇到问题。我已经在JSFIDLE中使用了这段代码,但它不能在引导程序中使用

这是

HTML

<div class="col-md-3 span6 privilege-container-b">
<label class="checkbox">
    <input type="checkbox" name="mypriv" value="test_priv1" class="test_priv1">Checkbox 1</label>
<label class="checkbox">
    <input type="checkbox" name="mypriv" value="test_priv2" class="test_priv2">Checkbox 2</label>
<label class="checkbox">
    <input type="checkbox" name="mypriv" value="test_priv3" class="test_priv3">Checkbox 3</label>
<label class="checkbox">
    <input type="checkbox" name="mypriv" value="test_priv4" class="test_priv4">Checkbox 4</label>
<label class="checkbox">
    <input type="checkbox" name="mypriv" value="test_priv5" class="test_priv5">Checkbox 5</label>
<label class="checkbox">
    <input type="checkbox" name="mypriv" value="test_priv6" class="test_priv6">Checkbox 6</label>
</div>

上面的代码不起作用。我的目标是,如果选中了test_priv1,那么test_priv2和test_priv3将被选中并锁定。我的代码有什么问题吗?请纠正我,伙计们。谢谢

我会在文本选择器中添加点,然后


你能提供一个它不工作的例子吗?在
中的
test_priv3
之前缺少
。test_priv2,.test_priv3'
请看,我很抱歉输入错误,我很恼火为什么它在我的jsp中不工作:(但是它可以在Fiddle上运行)您是否将代码放在dom就绪处理程序中?浏览器控制台中是否有错误?输入元素是否使用其他脚本动态创建
$('.test_priv1').change(function () {
    var val = $('.test_priv1').is(':checked');
    if (val === true) {
        $('.test_priv2, test_priv3').prop('checked', true);
        $('.test_priv2, test_priv3').prop('disabled', true);
    } else {
        $('.test_priv2, test_priv3').prop('checked', false);
        $('.test_priv2, test_priv3').prop('disabled', false);
    }
    return false;
});
$(function() {
    $('.test_priv1').on("click", function () { // IE<9 triggers change after blurred
        var checked = $(this).is(':checked');
        var $otherChecks = $('.test_priv2, .test_priv3');
        $otherChecks.prop('checked', checked);
        $otherChecks.prop('disabled', checked);
        $otherChecks.parent().toggleClass("disabled",checked);
    });
});
var $otherChecks = $("input[name='mypriv']:not('.test_priv1')");
var $otherChecks = $("input[name='mypriv']").not(this);