i漂泊

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3722|回复: 0

JQ checkBox全选,反选,取消

[复制链接]
TA的礼物信息
  • 收到:0
  • 送出:2
发表于 2014-7-9 18:09:27 | 显示全部楼层 |阅读模式
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
  6. <link href="css/ingrid.css" rel="stylesheet" type="text/css">
  7. <script language="JavaScript" src="jquery.min.js" type="text/javascript"></script>
  8. <SCRIPT LANGUAGE="JavaScript">
  9. <!--
  10. $("document").ready(function(){
  11.         $("#all").click(function(){   
  12.                 if(this.checked){   
  13.                         $("input[name='checkbox']").each(function(){this.checked=true;});
  14.                         $("#btn1").attr("value","反选");   
  15.                 }else{   
  16.                         $("input[name='checkbox']").each(function(){this.checked=false;});   
  17.                         $("#btn1").attr("value","全选");
  18.                 }   
  19.         });

  20.     $("#btn1").click(function(){     
  21.                 $("[name='checkbox']").attr("checked",'true');//全选
  22.      })
  23.     $("#btn2").click(function(){  
  24.                 $("[name='checkbox']").removeAttr("checked");//取消全选
  25.     })
  26.     $("#btn3").click(function(){         
  27.                 $("[name='checkbox']:even").attr("checked",'true');//选中所有奇数
  28.     })
  29.     $("#btn4").click(function(){      
  30.                 $("[name='checkbox']").each(function(){     
  31.                         if($(this).attr("checked")){
  32.                                 $(this).removeAttr("checked");
  33.             }else{
  34.                                 $(this).attr("checked",'true');
  35.                         }
  36.          })
  37.         })
  38.     $("#btn5").click(function(){
  39.                 var str="";
  40.         $("[name='checkbox'][checked]").each(function(){
  41.                         str+=$(this).val()+"/r/n";
  42.          })
  43.        alert(str);
  44.     })
  45. })
  46. //-->
  47. </SCRIPT>
  48.   
  49. </HEAD>

  50. <BODY>
  51. <form name="form1" method="post" action="">
  52.   <input type="checkbox" id="all" name="all">
  53.   <input type="button" id="btn1" value="全选">
  54.   <input type="button" id="btn2" value="取消全选">
  55.    <input type="button" id="btn3" value="选中所有奇数">
  56.   <input type="button" id="btn4" value="反选">
  57.   <input type="button" id="btn5" value="获得选中的所有值">
  58.    <br>
  59.   <input type="checkbox" name="checkbox" value="checkbox1">
  60.   checkbox1<br />
  61.    <input type="checkbox" name="checkbox" value="checkbox2">
  62. checkbox2<br />
  63.    <input type="checkbox" name="checkbox" value="checkbox3">
  64.   checkbox3<br />
  65.    <input type="checkbox" name="checkbox" value="checkbox4">
  66.    checkbox4<br />
  67.   <input type="checkbox" name="checkbox" value="checkbox5">
  68.    checkbox5<br />
  69.    <input type="checkbox" name="checkbox" value="checkbox6">
  70.    checkbox6<br />
  71.   <input type="checkbox" name="checkbox" value="checkbox7">
  72.   checkbox7<br />
  73.    <input type="checkbox" name="checkbox" value="checkbox8">
  74. checkbox8
  75. </form>

  76. </BODY>
  77. </HTML>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|IPiaoBo Inc. ( 渝ICP备17002826号 )

GMT+8, 2024-4-20 06:27 , Processed in 0.060777 second(s), 43 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表