What's the difference between putting script in head and body?

后端 未结 9 994
花落未央
花落未央 2020-12-04 12:15

I was getting a problem .


  

        
9条回答
  •  心在旅途
    2020-12-04 12:51

    What's the difference between putting script in head and body?

    The time that it runs.

    When I put scripts in head, the result shows 0 Shopping list

    The elements you are trying to access don't exist when the script runs (since they appear after the script in the document).

    Note that you can write a script so that a function is called later (for various values of later including "when the entire document has loaded") using event handlers.

提交回复
热议问题