JQuery 多個checkbox 只選中一個



   
   
  
  
          
  1. <form id="common-form">
  2. <input name="check1" type="checkbox"/>check1
  3. <input name="check2" type="checkbox"/>check2
  4. <input name="check3" type="checkbox"/>check3
  5. </form>

   
   
  
  
          
  1. $(function() {
  2.   $('#common-form').find('input[type=checkbox]').bind('click', function(){  
  3.           var id = $(this).attr("id");
  4.         
  5.         //當前的checkbox是否選中
  6.         if(this.checked){
  7.             //除當前的checkbox其他的都不選中
  8.             $("#common-form").find('input[type=checkbox]').not(this).attr("checked", false);
  9.             
  10.             //選中的checkbox數量
  11.             var selectleng = $("input[type='checkbox']:checked").length;
  12.             console.log("選中的checkbox數量"+selectleng);
  13.         }else{
  14.             //未選中的處理
  15.             console.log("未選中的處理");
  16.         }
  17.     });
  18. })



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM