jQuery - What are differences between $(document).ready and $(window).load?

前端 未结 8 2301
旧巷少年郎
旧巷少年郎 2020-11-22 02:45

What are differences between

$(document).ready(function(){
 //my code here
});

and

$(window).load(function(){
  //my code h         


        
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 03:38

    The Difference between $(document).ready() and $(window).load() functions is that the code included inside $(window).load() will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the document ready event fires before all images,iframes etc. are loaded, but after the whole DOM itself is ready.


    $(document).ready(function(){
    
    }) 
    

    and

    $(function(){
    
    });
    

    and

    jQuery(document).ready(function(){
    
    });
    

    There are not difference between the above 3 codes.

    They are equivalent,but you may face conflict if any other JavaScript Frameworks uses the same dollar symbol $ as a shortcut name.

    jQuery.noConflict();
    jQuery.ready(function($){
     //Code using $ as alias to jQuery
    });
    

提交回复
热议问题