Several methods js pages loaded and executed after the execution sequence

Js and jquery in use, a method often used to execute after the page loads. By finishing, probably five ways (of which there are only written in a different way).

1: using jQuery $ (function) {};

2: using jquery $ (document) .ready (function () {}); essentially no difference before both the first type are the kinds of shorthand. Two document is finished loading after the execution method.

3: using jQuery $ (window) .load (function () {});

4: Use window.onload = function () {} A third and fourth until the entire window is loaded to perform the method thereof. There is no difference between the two, just use a dom object using a jQuery object.

5: static binding on the label onload event, <body onload = "aaa ()"> wait for the body loading is completed, it will execute aaa () method.

Well, these five ways, the order of execution is kind of how it?

By below code verification found:

        Using 1: jQuery's $ (function) {} and 2: jquery's $ (document) .ready (function () {}); regardless of the position of where to place, always remaining three priority mode (Reason: both mode is performed after the document is loaded, the latter three is to wait until the entire page load has finished executing window), the order of execution between the two is who is at the top who takes precedence.

        Use 3: jQuery the $ (window) .load (function () {});

    4: window.onload = function bbb () {} the two, always take precedence over <body onload = "aaa ()"> performed. They both also based on the implementation of the order who over who should perform.

       Use 5: <body onload = "aaa ()"> always the last execution.

 

 1 <script type='text/javascript'>
 2 
 3   window.onload = function(){
 4     alert("页面加载完成====》onload");
 5   }
 6 
 7   $(window).load(function(){
 8     alert("jquery===》window load" );
 9   })
10 
11   $(document).ready(function () {
12     alert("jquery====》document ready");
13   });
14 
15   $(function(){
16      Alert ( " jQuery ====" the onload Document " );
 . 17    });
 18 is  
. 19    function AAA () {
 20 is      Alert ( " static tag ==== "the onload " );
 21 is    }
 22 is  
23 is </ Script>

This link: https://www.cnblogs.com/yifeixue/p/11543250.html

Such as reprint articles, please indicate the source, thank you!

 

This article from: https://www.cnblogs.com/Loveonely/p/8118256.html

Guess you like

Origin www.cnblogs.com/yifeixue/p/11543250.html