我有HTML代码:
<input type="checkbox" name="all" value="all">ALL
<input type="checkbox" name="agent" value="agent" >Agent
<input type="checkbox" name="company" value="company">Company
<input type="checkbox" name="branch" value="branch">Branch
如果我全部选中,其他复选框将被禁用,如果我取消选中,其他复选框将重新启用。
我尝试使用下面的脚本执行此操作。
$("input[name='all']").change(function() {
if(this.checked) {
$("input[name='agent']").prop("disabled",true);
}
});
您的代码只会做禁用的一部分。您应该使用checked
value作为Disabled属性来根据检查/取消检查状态来切换状态:
var subinputs = $("input[name=agent],input[name=company],input[name=branch]");
$("input[name='all']").change(function() {
subinputs.prop("disabled",this.checked);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="all" value="all">ALL
<input type="checkbox" name="agent" value="agent" >Agent
<input type="checkbox" name="company" value="company">Company
<input type="checkbox" name="branch" value="branch">Branch
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句