One, JavaScript automatic loading
① in text with onload: When all the contents of the page (including pictures) are loaded, then the onload is executed as follows:
1 <body onload= "alert (1)" ></body> <!--when there is an onload--2 <body onload= " Alert (2), alert (3), alert (4) ></body> <!--when more than one onload is separated by semicolons, pops up 2 3 4--
② in script window.onload: When all the contents of the page (including pictures) are loaded, then execute the window.onload, as follows:
Window.onload = function () {...}; The correct notation, which is the anonymous function//------------↓ multiple window.onload error notation-------------window.onload = function () {alert ("Text1");}; Do not execute window.onload = function () {alert ("Text2");}; Execute//------------↑---------------------------------------//------------ ↓ correct notation for multiple window.onload---------------------------window.attachevent ("onload", function () {alert (' a ')}); Window.attachevent ("onload", function () {alert (' B ')}), Window.attachevent ("onload", function () {alert (' C ')});// Key Note: In IE browser (window.attachevent), will pop up C B A///Key Tip: Other browser under (Window.addeventlistener), will pop up a b c//------------ ↑-----------------------------------------------------
Second, jquery automatic loading
① when the DOM structure (not including the picture) in the page is loaded and then executed (possibly the DOM element associated with something that is not loaded), there are three ways to do this:
$ (document). Ready (function () {...}); /notation 1, full name $ (function () {...}); Notation 2, Shorthand jQuery (function ($) {...}); Notation 3, shorthand
All elements (including pictures) in the ② page are loaded and completed before they are executed, as follows.
$ (window). Load (function () {...}); equals the JavaScript notation, such as Window.onload = function () {...};
③ immediately executes the anonymous function. When an anonymous function is enclosed and then appended with a parenthesis, the anonymous function can be run immediately, in two ways, as follows:
(function () {...}) (); Notation 1, no parameters (function ($) {...}) (JQuery); Notation 2, adding parameters to avoid conflicts with other variables
by Imp Pser
JavaScript and jquery Automatic loading method