<script src='你的 js 文件名'></script>
<script>
  abc();
</script>

解决方案 »

  1.   

    注意编码问题,如果编码不一致,加上 charset 属性
      

  2.   

    index.html<!DOCTYPE html>
    <html>
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <script src="./function.js" type="text/javascript"></script>
            <script>
                window.onload = function() {
                                abc();
                };
            </script>
        </head>
        <body>
            <div id="div1"></div>
        </body>
    </html>function.jsfunction abc() {
        var d1 = document.getElementById('div1');
    console.log(d1);
    }
      

  3.   

    放在最下面的form之上引用。有可能页面加载时候这个div1还没加载,这abc有哪个控件引用了吗?还是哪个动作引用它?例如点击,双击等?
      

  4.   

    <div id='div1'></div>這個要放在你的script上面。