Can you have multiple $(document).ready(function(){ … }); sections?

前端 未结 11 1374
庸人自扰
庸人自扰 2020-11-22 13:21

If I have a lot of functions on startup do they all have to be under one single:

$(document).ready(function() {

or can I have multiple such

11条回答
  •  日久生厌
    2020-11-22 13:52

    You can even nest document ready functions inside included html files. Here's an example using jquery:

    File: test_main.html

    
    
    
        
    
    
    
        

    test_main.html

    File: test_embed.html

    test_embed.html

    Console output:

    test_main.html READY                       test_main.html:15
    test_embed.html READY                      (program):4
    

    Browser shows:

    test_embed.html

提交回复
热议问题