When is document and document. All used?

Source: Internet
Author: User

< Body >
< Div ID = "AA" > 123456 </ Div >
< Input Type = "Button" Value = "An error occurs when document is used" Onclick = "Alert (document. AA. innertext );" />
< BR />
< Input Type = "Button" Value = "Document. All is not used here" Onclick = "Alert (document. All. AA. innertext );" />
</ Body >

RunCode.

If the name attribute is set in the HTML Tag corresponding to a, form object, image object, and Applet object, its value will be used as the property name of the Document Object, it is used to reference the corresponding object. Other objects are not allowed.
In addition, if input is used as a child element of form, inputname or document is used directly. it is incorrect to reference this object using inputname. formname must be used. inputname reference. Otherwise, you can use inputname to reference it.
In addition, we should note that many elements that are commonly used do not have a name.
If you want to reference an element with an ID, you can only use ID or document. getelementbyid, document. All. ID to reference it.
But an element like this, so it is like <a href = "...... "Name =" linkname "id =" linkid "> ...... </a>
Available
Linkid. href;
Linkname. href;
Document. All. linkid. href;
Document. All. linkname. href;
Document. getelementbyid ("linkid"). href;
Document. getelementsbyname ("linkname") [0]. href to reference

All is a set that contains all HTML objects. You can write a program to access all objects. Like this:
<Script language = "JavaScript">
VaR OBJ = "";
For (I = 0; I <document. All. length; I ++)
OBJ + = Document. All [I]. tagname + ";";
Alert (OBJ );
</SCRIPT>
Put the program after

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.