<form> <inputtype= "checkbox"name= "Hobby"ID= "Hobby1"/>Music<inputtype= "checkbox"name= "Hobby"ID= "Hobby2"/>Mountaineering<inputtype= "checkbox"name= "Hobby"ID= "Hobby3"/>Swimming<inputtype= "checkbox"name= "Hobby"ID= "Hobby4"/>Read<inputtype= "checkbox"name= "Hobby"ID= "Hobby5"/>Play<inputtype= "checkbox"name= "Hobby"ID= "Hobby6"/>Running<BR/> <inputtype= "button"value= "Select All"onclick= "Checkall ()"/> <inputtype= "button"value= "All is not selected"onclick= "ClearAll ()"/> <P>Select your preference number, number 1-6</P> <inputtype= "text"name= "WB"ID= "WB"/> <inputtype= "button"value= "OK"onclick= "Checkone ()"/> </form>
<script type= "Text/javascript" >//All selected FunctionsfunctionCheckall () {varHobby = document.getElementsByTagName ("Input"); for(vari=0;i) { if(hobby[i].type== "checkbox") {hobby[i].checked=true; } }}//All-Unchecked functionsfunctionClearAll () {varHobby = Document.getelementsbyname ("Hobby"); for(vari=0;i) {hobby[i].checked=false; }}//Select the selected Radio boxfunctionCheckone () {varJ=document.getelementbyid ("WB"). Value; varHobby=document.getelementbyid ("hobby" +j); Hobby.checked=true;}</script>
Conclusion:
By example, people can identify the identity of the identity card, have the name, there are categories (adults, children, the elderly) and so on.
1. ID is a person's identity card number, is unique. So by getElementById get a designated person.
2. Name is his name and can be repeated. So get a collection of people with the same name by Getelementsbyname.
3. TagName can appear to be a class, getElementsByTagName get the same class of people collection. getElementsByTagName ("Children"), such as children, are available.
(4.17) The difference between getelementbyid,getelementsbyname,getelementsbytagname