本文介绍了如果使用jquery选择其中两个,请禁用其他复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有以下4个复选框。 < input type =checkboxid =41name = 4 []value =abcstyle =width:10px>< / td> < input type =checkboxid =42name =4 []value =qwestyle =width:10px>< / td> < input type =checkboxid =43name =4 []value =xyzstyle =width:10px>< / td> < input type =checkboxid =44name =4 []value =pqrstyle =width:10px>< / td> 如果我选择其中两个复选框,我需要一种方法。 $ b 解决方案您可以使用: $ b $ b $(:checkbox [name ='4 []'] :checkbox [name ='4 []']:checked)。length == 2) $(':checkbox:not(:checked)')。prop('disabled',true); else $(':checkbox:not(:checked)')。prop('disabled',false); } 工作演示 I am having below 4 checkboxes.<input type="checkbox" id="41" name="4[]" value="abc" style="width:10px"></td><input type="checkbox" id="42" name="4[]" value="qwe" style="width:10px"></td><input type="checkbox" id="43" name="4[]" value="xyz" style="width:10px"></td><input type="checkbox" id="44" name="4[]" value="pqr" style="width:10px"></td>I need a way to disabled other checkboxes if I select two of them.Any help would be much appreciated. 解决方案 You can use:$(":checkbox[name='4[]']").change(function(){ if ($(":checkbox[name='4[]']:checked").length == 2) $(':checkbox:not(:checked)').prop('disabled', true); else $(':checkbox:not(:checked)').prop('disabled', false); });Working Demo 这篇关于如果使用jquery选择其中两个,请禁用其他复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 13:04