Executing JavaScript in the <head>, getElementById returns null

前端 未结 3 1196
旧巷少年郎
旧巷少年郎 2021-01-05 00:49

I have following code





        
3条回答
  •  情话喂你
    2021-01-05 01:37

    By the time the script is parsed, only the and tags have been loaded. There are several ways you can fix this:

    1. Put the
    2. Wrap the entire function in window.onload = function () { yourCodeHere(); }, which will halt execution of your code until the window has loaded.

提交回复
热议问题