Home >Web Front-end >JS Tutorial >A relatively complete summary and case of document.all_Basic knowledge

A relatively complete summary and case of document.all_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:42:28979browse

1.
document.all is a collection of all elements in the page. For example:
document.all(0) means the first element in the page
2.

Copy code Code As follows:

document.all can determine whether the browser is IE
if(document.all){
alert("is IE!");
}

3.
You can also set the id attribute (id=aaaa) to an element, and then call the element using document.all.aaaa
4.
Case:
Code 1:
Copy code The code is as follows:





Code 2:
But often name It can be the same (for example: using checkbox to get multiple hobbies of the user)
Copy code The code is as follows:






Code 3:
Theoretically the id in a page is Different from each other, if different tags have the same id
document.all.id will fail, like this:
Copy code The code is as follows:





Code 4:
For a complex page (the code is very long, or the ID is automatically generated by the program), or a
program written by a JavaScript beginner, it is very likely that two tags have the same ID.
In order to avoid errors when programming, I recommend writing like this:
Copy the code The code is as follows:








Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn