本文實例講述了JQuery限制復選框checkbox可選中個數的方法。分享給大家供大家參考。具體分析如下:
由于項目需要限制可批量操作的文件個數 所以寫了一段小代碼 
如果選中個數大于允許的最大個數 其他復選框不能選擇 
如果小于則所有復選框都能選擇
<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>希望本文所述對大家的jQuery程序設計有所幫助。
新聞熱點
疑難解答