Home > Web Front-end > JS Tutorial > JS document.all function usage example_Basic knowledge

JS document.all function usage example_Basic knowledge

WBOY
Release: 2016-05-16 17:06:14
Original
1164 people have browsed it

1.
document.all is a collection of all elements in the page. For example:
document.all(0) represents the first element in the page
2.
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 with 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 ids in a page are different from each other. If If different tags have the same id
document.all.id, it will fail, like this:
Copy code Code As follows:





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

Copy the code The code is as follows:









Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template