作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我在 bootstrap 3 中执行此操作时遇到问题。我有此代码在 jsfiddle 中工作,但它无法在 bootstrap 中工作。
这是jsfiddle
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>
Jquery
$('.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;
});
上面的代码不起作用。我的目标是,如果检查 test_priv1,则将检查并锁定 test_priv2 和 test_priv3。我的代码有什么问题吗?请大家指正。谢谢
最佳答案
我会将点添加到 text_priv3 选择器中并执行
$(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);
关于javascript - 检查一组复选框是否在 Bootstrap 中选中。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23884139/
我是一名优秀的程序员,十分优秀!