Jquery - if page loaded

后端 未结 9 1691
[愿得一人]
[愿得一人] 2021-02-05 15:57

Is there any trick how to start a function in javascript, which starts when the page is completely loaded?

9条回答
  •  你的背包
    2021-02-05 16:15

    If you mean when the HTML document has loaded, use the ready event:

    $(document).ready(function(){
      ...
    });
    

    Or the shorthand:

    $(function(){
      ...
    });
    

    If you mean when the page including all style sheets, scripts, images and whatnot has completed loading, use the load event:

    $(window).load(function(){
      ...
    });
    

提交回复
热议问题