In the development of the first few projects encountered onload use of several situations
1. Can be executed inside the body
<body onload= "alert (123)" ></body>
2. First define the page after the completion of the load use
Copy Code code as follows:
<script type= "Text/javascript" >
function Test () {
var aa = "hee, you big pig";
alert (AA);
}
window.onload = test;
</script>
Annotations: Here's window.onload = test; Do not add () after test because this is the method that triggers the event association
If added () will immediately trigger the execution of this method (which may not be our intention)
3. Using Anonymous functions
<script>window.onload = function () {alert (321);} </script>
4. js in the OnLoad multiple events how to write?
<1> <body onload= "AA (); BB (); CC ()" > separated by semicolons.
<2>
Window.attachevent ("onload", function () {alert (' a ')});
Window.attachevent ("onload", function () {alert (' B ')});
Window.attachevent ("onload", function () {alert (' C ')});
Annotations: The event registered after using the Attachevent registration event executes first
The example above will pop up C B A
Another point: This method can only be used under IE (window.attachevent)