我有一个asp.net weform,在一个页面上我有7个复选框,我之后是什么,如果第一个复选框被选中,那么剩下的6个被禁用,否则如果一个复选框(2-6)被选中我希望第一个被禁用。
此外,如果用户从2 - 6中选择2个或更多复选框,那么只有在取消选中后才能启用第一个复选框。
HTML
<div class="form-group">
<div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">All services</div>
<div class="col-sm-1">
<asp:CheckBox ID="Step02AllServices" runat="server" />
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Site content uploading only</div>
<div class="col-sm-1">
<asp:CheckBox ID="Step02ContentUploading" runat="server" />
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Site content & layout checking</div>
<div class="col-sm-1">
<asp:CheckBox ID="Step02ContentLayoutChecking" runat="server" />
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Testing on various browsers</div>
<div class="col-sm-1">
<asp:CheckBox ID="Step02TestingVariousBrowsers" runat="server" />
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Testing all website functionality</div>
<div class="col-sm-1">
<asp:CheckBox ID="Step02TestingFunctionality" runat="server" />
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Responsive design layouting only</div>
<div class="col-sm-1">
<asp:CheckBox ID="Step02ResponsiveLayouting" runat="server" />
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Responsive design layout testing</div>
<div class="col-sm-1">
<asp:CheckBox ID="Step02ResponsiveTesting" runat="server" />
</div>
</div>
答案 0 :(得分:1)
$(document).on('click', ':checkbox', function(){
$(":checkbox:not('#Step02AllServices')").attr('disabled', $('#Step02AllServices').is(':checked')); //disabled checkBoxes if 1st is checked
$("#Step02AllServices").attr('disabled', $(":checkbox:not('#Step02AllServices')").is(':checked'));//disabled 1st checkBoxe if any except 1st is checked
});
如果我理解正确的话......
最后一个案例我不明白
另外,正如我记得ASP.Net为其元素的ID添加一些前缀。要禁用此功能,您可以向元素添加此部分ClientIDMode="Static"
答案 1 :(得分:-1)
给他们所有相同的类,如“复选框”或其他东西。然后在准备好的文件中:
$("#AllClear").on("click", function() {
$(".checkbox").attr("checked", false);
}