How to run a function when the page is loaded?

前端 未结 9 1632
小鲜肉
小鲜肉 2020-11-22 11:02

I want to run a function when the page is loaded, but I don’t want to use it in the tag.

I have a script that runs if I initialise it in th

9条回答
  •  天涯浪人
    2020-11-22 12:06

    Take a look at the domReady script that allows setting up of multiple functions to execute when the DOM has loaded. It's basically what the Dom ready does in many popular JavaScript libraries, but is lightweight and can be taken and added at the start of your external script file.

    Example usage

    // add reference to domReady script or place 
    // contents of script before here
    
    function codeAddress() {
    
    }
    
    domReady(codeAddress);
    

提交回复
热议问题