It is rare to use JavaScript to select all items in the CheckBox. This is a gift carefully prepared by the author. The code is highly authenticated and well understood. I hope it will help you.
JavaScript implements the CheckBox method to select all items:
- <Html>
- <Head>
- <Title>
- Title>
- <Body>
- <Form Name="Form1">
- <Input Name="Allbox" Type="Checkbox" OnClick="TA ();" Title="Select or clear all selected projects" Tabindex="105">Select or clear all selected projects
- <Br/>
- <Span Class="X">
- <Input Type="Checkbox" Name="ABC" Class="" OnClick="TTA (this );">Qingming Festival Span>
- <Br/>
- <Span Class="X">
- <Input Type="Checkbox" Name="DEF" Class="" OnClick="TTA (this );">Changjiang Span>
- <Br/>
- <Span Class="X">
- <Input Type="Checkbox" Name="GHL" Class="" OnClick="TTA (this );">Hey, test Span>
- <Br/>
- Form>
- <Script Language="Javascript">
- VarFrm=Document. Form1;
- Script>
- <Script Language="JavaScript">
- Function TA (isO, noHL ){
- VarTrk=0;
- For (varI=0; I<Frm. elements. length; I ++ ){
- VarE=Frm. Elements [I];
- If (e. name! = 'Allbox ')&&(E. type= 'Checkbox ')){
- E. checked=Frm. Allbox. checked;
- If (frm. allbox. checked ){
- //E. parentElement. className="H"; //. ParentElement is not compatible with firefox
- E. parentNode. className="H"; // Call to set the parent node element class to change the background color
- } Else {
- E. parentNode. className="X"; // Call to set the parent node element class to change the background color
- }
- }
- }
- }
- Function TTA (CB, noHL ){
- If (CB. checked ){
- CB. parentNode. className="H";
- } Else {
- CB. parentNode. className="X";
- }
- VarTB=TO= 0;
- For (varI=0; I<Frm. elements. length; I ++ ){
- VarE=Frm. Elements [I];
- If (e. name! = 'Allbox ')&&(E. type= 'Checkbox ')){
- TB ++;
- If (e. checked)
- TO ++;
- }
- }
- Frm. allbox. checked= (TO= TB )? True: false;
- // If not all items are selected, allbox settings are not selected.
- }
- Script>
- <Style>
- . H {
- Background: # ADD8E6
- }
- . X {
- Background: # FFFFFF
- }
- Style>
- Body> Html>
The above is a brief introduction to the methods used to select all items in the CheckBox in JavaScript.
- What is JSON? Data format prepared for JavaScript
- 10 most commonly used JavaScript udfs
- Some extended thoughts on loading JavaScript events
- Summary of JavaScript usage: From BOM and DOM
- How ExtJS works on Android Simulators