document.all usage

Source: Internet
Author: User

One.

Document.all is a collection of all elements within a page. For example:

DOCUMENT.AA (0) represents the first element within a page

Two.

Document.all can tell if the browser is IE

if (document.all) {  alert ("is ie!") );}

Three.

You can also invoke the element with DOCUMENT.ALL.AAAA by setting the ID property (ID=AAAA) for an element.

Four.

Case:

Code Listing 1:

<inputname= "AAA"value= "AAA"><inputID= "BBB"value= "BBB"><Script>alert (document.all.aaa.value)//take value by namealert (document.all.bbb.value)//take value by ID</Script>

Code Listing 2:

But often the name can be the same (for example, using a checkbox to take a user's many hobbies)

<inputname= "AAA"value= "A1"><inputname= "AAA"value= "A2"><inputID= "BBB"value= "BBB"><Script>alert (DOCUMENT.ALL.AAA (0). Value)//Show A1alert (DOCUMENT.ALL.AAA (1). Value)//Show A2alert (DOCUMENT.ALL.BBB (0). Value)//This line of code will fail</Script>

Code Listing 3:

In theory, the ID of a page is different from each other, and if there are various tags with the same id,document.all.id will fail, like this:

<inputID= "AAA"value= "A1"><inputID= "AAA"value= "A2"><Script>alert (document.all.aaa.value)//show undefined instead of A1 or A2</Script>

Code Listing 4:

For a complex page (the code is very long, or the ID is automatically generated by the program), or a JavaScript beginner to write a program, it is likely to appear two tags have the same ID case. In order to be programmed without error, it is recommended that:

<inputID= "AAA"value= "Aaa1"><inputID= "AAA"value= "Aaa2"><inputname= "BBB"value= "BBB"><inputname= "BBB"value= "Bbb2"><inputID= "CCC"value= "CCC"><inputname= "DDD"value= "DDD"><Script>alert (document.all ("AAA",0). Value); Alert (document.all ("AAA",1). Value); Alert (document.all ("BBB",0). Value); Alert (document.all ("BBB",1). Value); Alert (document.all ("CCC",0). Value); Alert (document.all ("DDD",0). value);</Script>

Source: http://www.cnblogs.com/uedt/articles/1691443.html

document.all usage

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.