_addLoadEvent this method is to determine whether onload has been called multiple times, and if it is called multiple times, the multiple calls will be executed in Window.onload in turn
In fact, it's very simple, _addLoadEvent (func), pass a function in, and then determine whether window.onload has "bound" a function (i.e. typeof(window.onload) != 'function'), and if not, directly execute the passed func function. If it has been "bound", then define both the old function and the new function inside window.onload and execute it at once. i.e.: window.onload = function(){ oldonload(); func(); }
If a page has multiple window.onload definitions, only the last definition is often executed.
Let's talk about the difference between window.onload, $(document).ready(function(){}), and $(window).load(function(){})!
First, compare window.onload with $(document).ready(function(){}).
1. Execution time window.onload must wait until all elements of the page, including images, are loaded. $(document).ready()YesThe DOM structure is executed after it is drawn, without waiting for it to load。
2. Write the number
window.onload cannot be written at the same time, if there are multiple window.onload methods, it will only be executedOne $(document).ready() can be written at the same timemultiple, and can be executed
3. Simplify the writing method
window.onload is not simplified $(document).ready(function(){}) can be abbreviated as $(function(){});
The difference between $(window).load(function(){}) and window.onload is that $(window).load(function(){}) can write multiple times
|