1, window.onload in $ (document). Ready () after execution
Cause: Both trigger or not, are based on the document.readystate attribute.
(1) Value of document.readystate: Uninitialized, loading, interactive, complete (these four values, sorted by time).
(2) When its value is interactive, the documentcontentloaded event is triggered, and Jquery.ready () is a function designed for the documentcontentloaded event. This executes the task queue defined by the Jquery.ready.
(3) When the value is complete, the Load event is triggered.
(4) In summary, Window.onload will be executed after $ (document). Ready ().
Original agreement: document .readyState
Returns " loading
Document
while the is loading," interactive
"once it was finished parsing but still loading sub-resources, and" "Once it has loaded.
The readystatechange
event fires on the Document
object and this value changes.
2, window.onload multiple assignments will produce coverage, and $ (document). Ready () does not.
Reason:
(1) onload is a member method of the Window object and is a reference to an object of type function in heap memory. Because JavaScript does not have a function overloading mechanism, assigning a value to the onload multiple times causes the last reference to a function to be dismissed, instead referring to the reference to the current function, resulting in an overlay.
(2) $ (document). Ready () Implements a task object, passing in the function multiple times, adding a member to the task queue.
The difference between JavaScript Tips:window.onload and $ (document). Ready ()