js文件在html文件中的使用

刚开始学习JS。按照JavaScript DOM 编程艺术一书打了几行代码,但是却实现不了。
html文件内容如下:

<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>Just a test</title>
</head>
<body>
    <script type="text/javascript"             src="C:\Users\dwj\Desktop\html\example.js"></script>
</body>
</html>

js文件内容如下:

    var heigth="about 5'10\" tall";
    alert(height);

运行html文件后界面显示空白,js文件和html文件在同一目录下。不知道问题出在哪里了,求指点~

阅读 6.8k
2 个回答

变量名错了

var heigth="about 5'10\" tall";
alert(height);

同路径下可以直接用相对路径

<script src="example.js"></script>

确实会显示成空白

上面代码只是弹出了提示框T_T

If the HTML file and the script are in the same directory, use <script type="text/javascript" src="example.js"></script> directly.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题