<Html> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Example 2:
Functions to be implemented:
The js Code of the all-selected checkbox is as follows:
Var status = true;
Function allselect (){
Var tags = document. getElementsByTagName ("input ");
For (I = 0; I <tags. length; I ++)
{
If (tags [I]. type = "checkbox ")
{
Tags [I]. checked = status;
}
}
Status =! Status;
}
When you click show position, apply for the selected position, and add it to favorites, The js Code is as follows:
Function panduan (){
Var gou = 0;
Var tags = document. getElementsByTagName ("input ");
For (I = 0; I <tags. length; I ++)
{
If (tags [I]. type = "checkbox ")
{
If (tags [I]. id! = "Checkbox1") {// here, Checkbox1 is the all-selected checkbox
If (tags [I]. checked = true ){
Gou ++;
}
}
}
}
If (gou = 0 ){
Window. alert ("Please check the selected position! ");
Return false;
}
}
Example 3:
<HTML> <BODY> <input type = "checkbox" name = "huang" value = "ON"> <input type = "checkbox" name = "huang" value = "OFF "> <input type =" button "value =" checkall "onclick =" checkall (); "> <input type =" button "value =" centerall "onclick =" centerall (); "> </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
By the way, let's take a look at the usage of getElementsByTagName.
Javascript provides two methods for getting document reference: getElementById and getElementsByTagName. the former returns an element reference pointing to an element with the specified Id attribute, and the latter returns an array of elements with this tag. The former is widely used and familiar with it, this article briefly explains the latter.
For example, to define a table with multiple td tags, you need to change the background color of the second cell. You can use getElementsByTagName. The Code is as follows:
......
<Table style = "width: 100%;">
<Tr> <td> 1 </td>
<Td> 2 </td>
<Td> 3 </td>
</Tr>
<Tr>
<Td> 4 </td>
<Td> 5 </td>
<Td> 6 </td>
</Tr>
<Tr>
<Td> 7 </td>
<Td> 8 </td>
<Td> 9 </td>
</Tr>
</Table>
......
Var tdObject = document. getElementsByTagName ("td"). item (1 );
TdObject. style. backgroundColor = "blue ";
......