(4.17) The difference between getelementbyid,getelementsbyname,getelementsbytagname

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.