How to make JavaScript execute after page load?

前端 未结 24 2315
孤城傲影
孤城傲影 2020-11-21 05:55

I\'m executing an external script, using a

24条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-21 06:29

    You can put a "onload" attribute inside the body

    ......
    

    Or if you are using jQuery, you can do

    $(document).ready(function(){ /*code here*/ }) 
    
    or 
    
    $(window).load(function(){ /*code here*/ })
    

    I hope it answer your question.

    Note that the $(window).load will execute after the document is rendered on your page.

提交回复
热议问题