Home > Web Front-end > JS Tutorial > body text

Page loading techniques for window.onload_javascript techniques

WBOY
Release: 2016-05-16 19:00:22
Original
1267 people have browsed it

After testing the two pieces of code separately, it was found that window.onload without brackets showed the correct effect after the page was loaded. I think window.onload is also equivalent to a trigger event. If the function has parentheses, the function will be executed directly first, and then the body will be loaded. Without parentheses, it is equivalent to assigning a function as a variable to window.onload and not loading it immediately.

Code 1:


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]


Code 2:

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute <script> window.onload = doIt(); function doIt() { var oDiv = document.getElementById("div1"); alert (oDiv); } </script>]<script> window.onload = doIt; function doIt() { var oDiv = document.getElementById("div1"); alert (oDiv); } </script>
Related labels:
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