webform1.aspx


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="JavascriptStudy.WebForm1"%> 

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="JavascriptStudy.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <title>WebForm1</title>
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
  <script language="javascript" type="text/javascript" src="./01.js"></script>
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <asp:checkbox id="CheckBox0" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server"
    p="x" ToolTip="x"></asp:checkbox><asp:checkbox id="CheckBox1" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 48px" runat="server"
    p="x" ToolTip="x"></asp:checkbox><INPUT id="Button1" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 96px" type="button"
    value="SelectAll"><INPUT style="Z-INDEX: 104; LEFT: 96px; POSITION: absolute; TOP: 96px" type="button" value="ClearAll"
    id="Button2"></form>
 </body>
</HTML>




01.js



window.onload=initAll;


function checkAll()
{
 var el=document.getElementsByTagName("span");
 for (var i=0;i<el.length;i++)
 {
  if (el[i].p=="x")
  {
   if (el[i].getElementsByTagName("input")[0].getAttribute("type")=="checkbox")
   {
    el[i].getElementsByTagName("input")[0].setAttribute("checked",true);
   }
  }
 }
}
function clearAll()
{
 var el=document.getElementsByTagName("span");
 for (var i=0;i<el.length;i++)
 {
  if (el[i].p=="x")
  {
   if (el[i].getElementsByTagName("input")[0].getAttribute("type")=="checkbox")
   {
    el[i].getElementsByTagName("input")[0].setAttribute("checked",false);
   }
  }
 }
}

function initAll()
{
 document.getElementById("Button1").onclick=checkAll;
 document.getElementById("Button2").onclick=clearAll;
}