【发布时间】:2018-01-05 09:30:52
【问题描述】:
如果我选择了前一个复选框,我想禁用下一个复选框,这无关紧要,只有在单击前一个复选框时才应禁用下一个复选框,但不幸的是无法使其工作
以下是代码:
$(function() {
var next = $(".checkboxes").next().find(":checkbox");
//alert(next);
$('.checkboxes input[type=checkbox]').bind("click", function() {
if ($(this).is(':checked')) {
$(this).next().prop("disabled", true);
} else {
$(this).next().prop("disabled", false);
}
});
});
.checkboxes {
float: left;
width: 100%;
margin-bottom: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check1">Option1</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check2">Option2</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check3">Option3</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check4">Option4</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check5">Option6</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check6">Option6</label>
【问题讨论】:
-
$(this).closest("label").next().find("input[type=checkbox]").prop("disabled", true);? -
复选框在禁用时是否应该保持选中状态?
标签: javascript jquery html checkbox