欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery限制復(fù)選框checkbox可選中個(gè)數(shù)的方法

 更新時(shí)間:2015年04月20日 10:11:33   作者:feige  
這篇文章主要介紹了JQuery限制復(fù)選框checkbox可選中個(gè)數(shù)的方法,涉及jQuery操作復(fù)選框長(zhǎng)度判斷與屬性修改的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了JQuery限制復(fù)選框checkbox可選中個(gè)數(shù)的方法。分享給大家供大家參考。具體分析如下:

由于項(xiàng)目需要限制可批量操作的文件個(gè)數(shù) 所以寫了一段小代碼
如果選中個(gè)數(shù)大于允許的最大個(gè)數(shù) 其他復(fù)選框不能選擇
如果小于則所有復(fù)選框都能選擇

<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>

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論