1. 程式人生 > >HTML 中 checkbox 的全選

HTML 中 checkbox 的全選

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>C1 C2 C3 C4 C5 C6 C7 C8 C9</title>
</head>


<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
  function checkAll() {
     for (var j = 1; j <= 9; j++) {
        box = eval("document.checkboxform.C" + j);
        if (box.checked == false) box.checked = true;
     }
  }
  function uncheckAll() {
     for (var j = 1; j <= 9; j++) {
         box = eval("document.checkboxform.C" + j);
         if (box.checked == true) box.checked = false;
     }
  }
 
  function switchAll() {
      for (var j = 1; j <= 9; j++) {
      box = eval("document.checkboxform.C" + j);
      box.checked = !box.checked;
  }
}
//  End -->
</script>
<form name=checkboxform>
<input type=checkbox name=C1 checked>C1<br>
<input type=checkbox name=C2 checked>C2<br>
<input type=checkbox name=C3 checked>C3<br>
<input type=checkbox name=C4 checked>C4<br>
<input type=checkbox name=C5 checked>C5<br>
<input type=checkbox name=C6 checked>C6<br>
<input type=checkbox name=C7 checked>C7<br>
<input type=checkbox name=C8 checked>C8<br>
<input type=checkbox name=C9 checked>C9<br>
<br>
<input type=button value="全部選中" onClick="checkAll()"><br>
<input type=button value="全部不選" onClick="uncheckAll()"><br>
<input type=button value="選擇轉換" onClick="switchAll()"><br>
</form>

</body>

</html>

介面:
C1
C2
C3
C4
C5
C6
C7
C8
C9