The example in this article describes how JQuery limits the number of checkboxes that can be selected. Share it with everyone for your reference. The specific analysis is as follows:
Since the project needs to limit the number of files that can be operated in batches, I wrote a small code
If the number of selected items is greater than the maximum allowed number, other check boxes cannot be selected
If less than then all checkboxes can be selected
<script type="text/javascript"> $(document).ready(function() { $('input[type=checkbox]').click(function() { $("input[name='apk[]']").attr('disabled', true); if ($("input[name='apk[]']:checked").length >= 3) { $("input[name='apk[]']:checked").attr('disabled', false); } else { $("input[name='apk[]']").attr('disabled', false); } }); }) </script> <ul> <li> <input type="checkbox" name="apk[]" value=1 /> APK1 </li> <li> <input type="checkbox" name="apk[]" value=2 /> APK2 </li> <li> <input type="checkbox" name="apk[]" value=1 /> APK3 </li> <li> <input type="checkbox" name="apk[]" value=4 /> APK4 </li> <li> <input type="checkbox" name="apk[]" value=6 /> APK5 </li> <li> <input type="checkbox" name="apk[]" value=7 /> APK6 </li> <li> <input type="checkbox" name="apk[]" value=8 /> APK7 </li> </ul>
I hope this article will be helpful to everyone’s jQuery programming.