jQuery events .load(), .ready(), .unload()

前端 未结 4 692
情深已故
情深已故 2020-11-28 20:26

Just a simple question, for the jQuery event. Are the .load(), .ready() and .unload() run in order when the DOM is loaded? The answer seems yes when I see the jQuery Documen

4条回答
  •  天命终不由人
    2020-11-28 21:20

    window load will wait for all resources to be loaded.

    document ready waits for the document to be initialized.

    unload well, waits till the document is being unloaded.

    the order is: document ready, window load, ... ... ... ... window unload.

    always use document ready unless you need to wait for your images to load.

    shorthand for document ready:

    $(function(){
        // yay!
    });
    

提交回复
热议问题