Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2559437
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: 系统运维

2011-11-01 10:08:25

From:Unobtrusive Check/Uncheck Script

The following form contains two sets of checkboxs, one set given the className "chkboxgroup" (containing 3 checkboxs) and another noclassName at all (the last checkbox). The form itself has been given the className "fdCheckbox-chkboxgroup" which tells the script to create the check/uncheck buttons only for the group of checkboxs whose className includes (you guessed it), "chkboxgroup".

Additionally, no placeholder div is present and so the buttons are created as child elements of the form itself.

Multiple Checkbox group test 1

 : classname "chkboxgroup" 1

 : classname "chkboxgroup" 2

 : classname "chkboxgroup" 3

The following checkbox should be left untouched by the check/uncheck action as it does not have the className "chkboxgroup":

 : no classname

The following form contains two sets of checkboxs, one given the className "groupa" (containing 3 checkboxs) and another the className "groupb" (also containing 3 checkboxs). The form has been given the className "fdCheckbox-groupa fdCheckbox-groupb" which tells the script to create individual check/uncheck buttons for both groups of checkboxs.

Additionally, a placeholder div for the button creation has been positioned above both of the checkbox groups.

Multiple Checkbox group test 2

 : classname "groupa" 1

 : classname "groupa" 2

 : classname "groupa" 3

The second group of checkboxs given the classname "groupb" starts here.

 : classname "groupb" 1

 : classname "groupb" 2

 : classname "groupb" 3

Read the related post (and view the source code to get a better idea of whats going on behind the scenes).


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
  2. <html xmlns="" xml:lang="en" lang="en">
  3. <head>
  4. <title>frequency decoder - unobtrusive check/uncheck all form checkboxs demo</title>
  5. <link rel="stylesheet" type="text/css" href="/css/fdbasic.css" media="screen" />
  6. <script type="text/javascript">

  7. </script>
  8. <style type="text/css">
  9. body
  10.         {
  11.         padding:0;
  12.         border:0;
  13.         margin:0;
  14.         text-align:center;
  15.         font-family:georgia, Trebuchet MS, lucida grande, lucida sans unicode, Tahoma, verdana, arial, sans-serif;
  16.         font-size:11px;
  17.         line-height:16px;
  18.         font-family: "Lucida Grande","Lucida Sans Unicode",geneva,verdana,sans-serif;
  19.         color:#545454;
  20.         min-width: 800px;
  21.         border-top:3px solid #97BC45;
  22.         background:#fff url(../../media/gradient-e5e5e5-ffffff.gif) repeat-x 0 0;
  23.         }
  24. form
  25.         {
  26.         width:800px;
  27.         padding:10px;
  28.         text-align:left;
  29.         background:#eee;
  30.         border:1px solid #ccc;
  31.         margin:0 auto 20px auto;
  32.         }
  33. h1#frequency-decoder
  34.         {
  35.         margin:3em auto 2em auto;
  36.         }
  37. h2
  38.         {
  39.         text-align:center;
  40.         }
  41. p,
  42. fieldset,
  43. p.marginme
  44.         {
  45.         margin:0 0 1.4em 0;
  46.         }
  47. legend
  48.         {
  49.         font-weight:900;
  50.         color:#222;
  51.         }
  52. fieldset p
  53.         {
  54.         margin:0;
  55.         }



  56. </style>
  57. </head>
  58. <body>
  59.   <h1 id="frequency-decoder" title="frequency-decoder"><a href="/" title="there’s no place like home, there’s no place like home…"><span>frequency decoder</span></a></h1>
  60.   <h2>Unobtrusive Check/Uncheck script</h2>

  61.   <form action="" method="" class="fdCheckbox-chkboxgroup">
  62.     <p>The following form contains two <em>sets</em> of checkboxs, one set given the <code>className</code> "chkboxgroup" (containing 3 checkboxs) and another no <code>className</code> at all (the last checkbox). The form itself has been given the <code>className</code> "fdCheckbox-chkboxgroup" which tells the script to create the check/uncheck buttons only for the group of checkboxs whose <code>className</code> includes (you guessed it), "chkboxgroup".</p>
  63.     <p>Additionally, no placeholder <code>div</code> is present and so the buttons are created as child elements of the form itself.</p>
  64.     <fieldset>
  65.       <legend>Multiple Checkbox group test 1</legend>
  66.       <p>
  67.         <input type="checkbox" name="somename1" class="chkboxgroup" value="1" id="cb1" /> : <label for="cb1">classname "chkboxgroup" 1<br /></label>
  68.       </p>
  69.       <p>
  70.         <input type="checkbox" name="somename2" class="chkboxgroup" value="2" id="cb2" /> : <label for="cb2">classname "chkboxgroup" 2<br /></label>
  71.       </p>
  72.       <p class="marginme">
  73.         <input type="checkbox" name="somename3" class="chkboxgroup" value="3" id="cb3" /> : <label for="cb3">classname "chkboxgroup" 3<br /></label>
  74.       </p>
  75.       <p class="marginme">The following checkbox should be left untouched by the check/uncheck action as it does not have the <code>className</code> "chkboxgroup":</p>
  76.       <p><input type="checkbox" name="extrachkbox" value="1" id="ex" /> : <label for="ex">no classname<br /></label></p>
  77.     </fieldset>
  78.   </form>

  79.   <form action="" method="" class="fdCheckbox-groupa fdCheckbox-groupb">
  80.     <p>The following form contains two <em>sets</em> of checkboxs, one given the <code>className</code> "groupa" (containing 3 checkboxs) and another the className "groupb" (also containing 3 checkboxs). The form has been given the <code>className</code> "fdCheckbox-groupa fdCheckbox-groupb" which tells the script to create individual check/uncheck buttons for both groups of checkboxs.</p>

  81.     <p>Additionally, a placeholder <code>div</code> for the button creation has been positioned above both of the checkbox groups.</p>
  82.     <fieldset>
  83.       <legend>Multiple Checkbox group test 2</legend>
  84.       <div class="button-placeholder-groupa"> </div>
  85.       <p>
  86.         <input type="checkbox" name="groupa1" class="groupa" value="1" id="cb4" /> : <label for="cb4">classname "groupa" 1<br /></label>
  87.       </p>
  88.       <p>
  89.         <input type="checkbox" name="groupa2" class="groupa" value="2" id="cb5" /> : <label for="cb5">classname "groupa" 2<br /></label>
  90.       </p>
  91.       <p class="marginme">
  92.         <input type="checkbox" name="groupa3" class="groupa" value="3" id="cb6" /> : <label for="cb6">classname "groupa" 3<br /></label>
  93.       </p>
  94.       <p class="marginme">The second group of checkboxs given the classname "groupb" starts here.</p>
  95.       <div class="button-placeholder-groupb"> </div>
  96.       <p>
  97.         <input type="checkbox" name="groupb1" class="groupb" value="1" id="cb7" /> : <label for="cb7">classname "groupb" 1<br /></label>
  98.       </p>
  99.       <p>
  100.         <input type="checkbox" name="groupb2" class="groupb" value="2" id="cb8" /> : <label for="cb8">classname "groupb" 2<br /></label>
  101.       </p>
  102.       <p>
  103.         <input type="checkbox" name="groupb3" class="groupb" value="3" id="cb9" /> : <label for="cb9">classname "groupb" 3<br /></label>
  104.       </p>
  105.     </fieldset>

  106.     <p>Read the <a href="">related post</a> (and view the source code to get a better idea of whats going on behind the scenes).
  107.   </form>

  108. </body>
  109. </html>

另一个demo

  1. <script language="javascript">
  2. function checkAll(master){
  3. var checked = master.checked;
  4. var col = document.getElementsByTagName("INPUT");
  5. for (var i=0;i<col.length;i++) {
  6. col[i].checked= checked;
  7. }
  8. }
  9. </script>

  10. Master: <input type="checkbox" onclick="checkAll(this)"><br>
  11. Slave1:<input type="checkbox" ><br>
  12. Slave2:<input type="checkbox" ><br>

阅读(1524) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~