首页 > js文件在html文件中的使用

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文件在同一目录下。不知道问题出在哪里了,求指点~


变量名错了

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.

【热门文章】
【热门文章】