简体   繁体   中英

External javascript file in html not working

first post.. trying javascript for first time. i am following a book , created two files in the same directory test_js.html helloWorld.js

Contents of both are below: test_js.html

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

helloWorld.js

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

I dont see any alert when i load the html page. However if i embed the same alert("hello") in the html page, i am seeing the alert being displayed.

Tried this on chrome and firefox (both latest) with same result. Following googled examples is not showing any error in any of the files.

Please help.

remove script tags from helloWorld.js

just

alert("hello");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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