Script does not work when on <head>

后端 未结 3 1114
一向
一向 2020-12-11 09:37

I proved script. its works, but outside of . I am not good on script. maybe its a simple problem.




        
3条回答
  •  囚心锁ツ
    2020-12-11 10:01

    In some cases, if you are trying to operate on items that are on the page, if you javascript loads and executes before the rest of the page has finished loading, you will get errors and/or your code will not appear to work.

    This is one reason it is recommended to put links to javascript files at the bottom of the page.

    Another good practice is to only run your when the document has finished loading, in jQuery is is normally done using the following syntax:

    $(document).ready(function(){
       // Your javascript
    }
    

提交回复
热议问题