Home >Web Front-end >JS Tutorial >Detailed explanation of the difference between JQuery's ready function and JS's onload_jquery

Detailed explanation of the difference between JQuery's ready function and JS's onload_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:13:27904browse

The difference between JQuery's ready function and JS's onload:
1. Execution time
window.onload must wait until all elements in the page, including images, are loaded before it can be executed.
$(document).ready() is executed after the DOM structure is drawn, without waiting until it is loaded.


2. Different writing numbers
You cannot write multiple window.onloads at the same time. If there are multiple window.onload methods, only one will be executed.
$(document).ready() can be written at the same time Write multiple and all can be executed


3. Simplified writing
There is no simplified writing for window.onload
$(document).ready(function(){}) can be abbreviated as $(function(){});

" -//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

                                                                                                                                                           worse not have been the same? ;                                       //The onload attribute of the window object in js executes the jsFunction2 function
$(document) .ready(jqFunction1);

              //jquery’s ready method executes the jqFunction2 function unction1( ){
alert("jsFunction1");
}

//jsFunction2 function
function jsFunction2(){
alert( "jsFunction2");
}

//jqFunction1 function
function jqFunction1(){
alert("jqFunction1");
}

//jqFunction2 function
Function jqFunction2(){
         alert("jqFunction2");                                                       in js The difference between onload




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