In the development of previous projects, I encountered several situations in which onload was used
1. It can be executed in the Body
2. First define and use
Note: Here window.onload = test; Do not add () after test Because this is a method that is triggered by event association
If you add (), it will immediately trigger the execution of this method (this may not be our intention)
3. Use anonymous function
<script>window.onload = function(){alert(321);}</script>
4. How to write multiple onload events in JS?
<1> Just separate them with semicolons
<2>
window.attachEvent(" onload",function(){alert('a')});
window.attachEvent("onload",function(){alert('b')});
window.attachEvent("onload" ,function(){alert('c')});
Annotation: After using attachEvent to register the event, the registered event will be executed first
The above example will pop up C B A
One more thing :This method can only be used under IE (window.attachEvent)
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