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