简体   繁体   English

html 中的外部 javascript 文件不起作用

[英]External javascript file in html not working

first post.. trying javascript for first time.第一个帖子.. 第一次尝试 javascript。 i am following a book , created two files in the same directory test_js.html helloWorld.js我正在关注一本书,在同一目录 test_js.html helloWorld.js 中创建了两个文件

Contents of both are below: test_js.html两者的内容如下: test_js.html

<html>
<head>
<title> First Javascript page </title>
<script type="text/javascript" src="helloWorld.js"></script>
</head>
<body></body>
</html>

helloWorld.js你好世界.js

<script type="text/javascript">
alert("hello");
</script>

I dont see any alert when i load the html page.当我加载 html 页面时,我没有看到任何警报。 However if i embed the same alert("hello") in the html page, i am seeing the alert being displayed.但是,如果我在 html 页面中嵌入相同的警报(“你好”),我会看到正在显示警报。

Tried this on chrome and firefox (both latest) with same result.在 chrome 和 firefox(都是最新的)上试过这个,结果相同。 Following googled examples is not showing any error in any of the files.以下 googled 示例未显示任何文件中的任何错误。

Please help.请帮忙。

remove script tags from helloWorld.js从 helloWorld.js 中删除脚本标签

just只是

alert("hello");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM