When will the document and document.all respectively use _javascript?

Source: Internet
Author: User
<body>
<div id= "AA">123456</div>
<input type= "button" value= "There is an error with document" onclick= "alert ( Document.aa.innerText); " />
<br />
<input type= "button" value= "There is no error with document.all." onclick= "alert ( Document.all.aa.innerText); " />
</body>
Run the above code.

If the Name property is set in the HTML tag corresponding to the A,form object, the Image object, and the Applet object, its value will be used as the property name of the document object, to refer to the corresponding object, and not to other objects.
In addition, input and so on, if as a child element of a form, it is wrong to refer to this object directly with InputName or document.inputname, you must use Formname.inputname reference, Otherwise, you can use InputName to refer to.
It should also be noted that there are many elements that are normally used without name.
If you want to reference an element with an ID, you can only refer to it with an ID or document.getelementbyid,document.all.id
But like such elements, so like <a href= "..." name= "linkname" id= "LinkId" >......</a>
can use
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 collection that contains all the sets of HTML pairs, writing a program that can be accessed to all the image pairs. Like this:
<script language= "JavaScript" >
var obj= "";
for (i=0;i<document.all.length;i++)
Obj+=document.all[i].tagname+ ";";
alert (obj);
</script>
Note that you have to 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.