Code 2:
However, names can often be the same (for example, using checkbox to retrieve users' interests)
<Input name = aaa value = A1>
<Input name = aaa value = A2>
<Input id = BBB value = BBB>
<Script language = JScript>
Alert (document. All. AAA (0). Value) // display A1
Alert (document. All. AAA (1). Value) // display A2
Alert (document. All. BBB (0). Value) // This line of code will fail
</SCRIPT>
Code 3:
In theory, the IDs on a page are different from each other. If different tags have the same ID
Document. All. ID will fail, just like this:
<Input id = aaa value = A1>
<Input id = aaa value = A2>
<Script language = JScript>
Alert (document. All. AAA. Value) // display undefined instead of A1 or A2
</SCRIPT>
Code 4:
For a complex page (the code is long, or the ID is composed Automatically generated by the Program), or
A program written by a beginner in Javascript may have two tags with the same ID.
To avoid errors during programming, I recommend the following method:
<Input id = aaa value = aaa1>
<Input id = aaa value = aaa2>
<Input name = BBB value = BBB>
<Input name = BBB value = bbb2>
<Input id = CCC value = CCC>
<Input name = DDD value = DDD>
<Script language = JScript>
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>
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