Home > Web Front-end > JS Tutorial > body text

JQuery method to limit the number of checkboxes that can be selected_jquery

WBOY
Release: 2016-05-16 16:03:08
Original
1059 people have browsed it

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>
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!