[removed] document.getElementById() returns NULL

后端 未结 7 2052
遥遥无期
遥遥无期 2021-01-02 01:23

I am quite new with Javascript and I got a problem with document.getElementById() that always returns NULL, and that\'s driving me nuts.

I have a element in my code

7条回答
  •  别那么骄傲
    2021-01-02 01:36

    The page contents need to be loaded before trying to read them. Try

    window.onload = function() {
      // run your script in here
    }
    

    Or if you're using jQuery, prefer

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

提交回复
热议问题