多选全选jquery实现

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5. <title>多选反选</title>  
  6. <script type="text/javascript" src="../js/jquery-1.4.2.js"></script>  
  7. <script type="text/javascript">  
  8.     window.οnlοad=function(){  
  9.         $("#yesorno").click(function(){  
  10.             $("input[name=sport]").attr("checked",$(this).attr("checked"));  
  11.         });  
  12.       
  13.       
  14.     $("#allselect").click(function(){  
  15.         $("input[name=sport]").attr("checked",true);  
  16.     });  
  17.     $("#nothingselect").click(function(){  
  18.         $("input[name=sport]").attr("checked",null);  
  19.     });  
  20.       
  21.     $("#reverseselect").click(function(){  
  22.         $("input[name=sport]").each(function(){  
  23.             if($(this).attr("checked")){  //if(this.checked){  
  24.                 $(this).attr("checked",null);  
  25.             }else{  
  26.                 $(this).attr("checked",true);  
  27.             }  
  28.         });  
  29.     });  
  30.     };  
  31. </script>  
  32. </head>  
  33. <body>  
  34.     <input type="checkbox" id="yesorno"/>全选/全不选 <br/>  
  35.       
  36.     <input type="checkbox" name="sport" id="football" />足球  
  37.     <input type="checkbox" name="sport" id="basketball"/>蓝球  
  38.     <input type="checkbox" name="sport" id="volleyball"/>排球  
  39.     <input type="checkbox" name="sport" id="tennis"/>网球  
  40.     <br/>  
  41.     <input type="button" id="allselect" value="全选"/>  
  42.     <input type="button" id="nothingselect" value="全不选"/>  
  43.     <input type="button" id="reverseselect" value="反选"/>  
  44.       
  45. </body>  
  46. </html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值