< 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