Put getElementById() at the bottom

This question already has an answer here:

  • $(document).ready equivalent without jQuery 31 answers

  • You need to wait for your page to be ready before your code can execute on markup in the page. For example, use window.onload handler as in the example below. There are nicer ways to do this such as jQuery methods, but this will serve as an example of what you need.

    <html>
    <head>
        <script>
            window.onload = function ()
             {
                  document.getElementById("txt").innerHTML = "Hello";
             }
        </script>
    
    </head>
    <body>
    
    <div id="txt"></div>
    
    </body>
    </html>
    链接地址: http://www.djcxy.com/p/71250.html

    上一篇: JS中的jquery事件

    下一篇: 将getElementById()放在底部