jquery checkbox 限制多选的个数

寻技术 JQuery 2023年07月11日 69

2015年11月6日 16:32:49

选中第四个的时候提示超过了3个, 点解alert框取消后, 将最后一个选中的checkbox取消选中

 <script>
     $(document).ready(function (){
         $('input[type=checkbox]').click(function(){
             if ($("input[name='contract[]']:checked").length > 3) {
                 alert('最多选3个');
                 $(this).removeAttr("checked");
             }
         });
     });
 </script>

 

关闭

用微信“扫一扫”