JQuery限制複選框checkbox可選中個數的方法,jquerycheckbox

來源:互聯網
上載者:User

JQuery限制複選框checkbox可選中個數的方法,jquerycheckbox

本文執行個體講述了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程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.