jQuery document.ready vs pageLoad

后端 未结 6 1701
陌清茗
陌清茗 2021-02-02 11:56

I\'ve picked up an existing project from another developer and ive noticed in the code that they are executing js code within three different event handlers...

f         


        
相关标签:
6条回答
  • 2021-02-02 12:16

    pageLoad and the jQuery ready handler are both methods of accomplishing similar things.

    The second two examples are identical.

    http://encosia.com/document-ready-and-pageload-are-not-the-same/

    0 讨论(0)
  • 2021-02-02 12:24
    $(document).ready(function() {
    `enter code here`
    //execute code
    });
    
    $(function() {
    `enter code here`
    });
    

    Both functions perform task in the same way, executes code inside them once the document is ready.

    function pageLoad() {
    `enter code here`
    }
    

    This executes after every post back, generally used with update panels controls as the above two functions does not execute every time or every post back.

    0 讨论(0)
  • 2021-02-02 12:24

    $(document).ready() will not fire for the partial postbacks (happened from AJAX). In that case, you should use MS AJAX pageLoad function when you need to execute something when the page loads either from the full postback or partial.

    The article given in the Encosia site is a good read.

    0 讨论(0)
  • 2021-02-02 12:26

    $(document).ready()

    • Ideal for one time initialization.

    • Optimization black magic; may run slightly earlier than pageLoad().

    • Does not re-attach functionality to elements affected by partial postbacks.

    pageLoad()

    • Unsuitable for one time initialization if used with UpdatePanels.

    • Slightly less optimized in some browsers, but consistent.

    • Perfect for re-attaching functionality to elements within UpdatePanels.

    0 讨论(0)
  • 2021-02-02 12:33

    In this site you will find the difference :)

    Document.ready Vs pageLoad

    0 讨论(0)
  • 2021-02-02 12:41

    The last one is just a shorthand notation of the one above it. http://www.jquery4u.com/dom-modification/types-document-ready/

    0 讨论(0)
提交回复
热议问题