Home  >  Article  >  Web Front-end  >  Page loading techniques for window.onload_javascript techniques

Page loading techniques for window.onload_javascript techniques

WBOY
WBOYOriginal
2016-05-16 19:00:221228browse

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>
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