Difference between onload() and $.ready?

前端 未结 6 1582
灰色年华
灰色年华 2020-11-28 05:17

Can you list the difference between onload() and $(document).ready(function(){..}) functions in the using jQuery?

6条回答
  •  一个人的身影
    2020-11-28 05:25

    onload() fires when all the content (everything) on the targeted eleement is fully loaded like CSS, images etc.

    $.ready indicates that code in it need to be executed once the targeted elements content loaded and ready to be manipulated by script. It won't wait for the images to load for executing the jQuery script.

    .
    

    Ex(body onload):

    
    
    
    

    Ex(onload on an element):

    
    
    
    

    Ex3 ($.ready):

    
    

提交回复
热议问题