简体   繁体   中英

alert("Hello World"); Not Working

I was following along a Lynda tutorial and it seemed to be working fine, I shutdown my computer and the next day, the javascript to pop up a dialog is not working when I launch the html page in Chrome, IE, Edge, Etc.

I have the most minimal html page and have it connected to my script.js file.

I've checked for most errors.

alert("Hello");

It just won't prompt it.

I've recently tried to recreate it 3-4 times, so there may be new errors.

HTML

<head>
    <title> Practice </title>
</head>

<body>
    <p>Practice HTML and Javascript</p>
    <script src="script.js"></script>
</body>

JAVASCRIPT

alert("Hello World");

I got the stuff to work. Here is what I did:

  • I named my files with .html and .js extensions, which were removed (maybe by default) and were not visible when viewing them in the file browser.

  • I added the extensions again thinking I had made an error, so the wrong file name was being referenced in the html. It was script.js.js instead of script.js which was wrong.

Try running your Javascript Code within your HTML file.

<head>
     <title> Practice </title>
</head>

<body>
    <p>Practice HTML and Javascript</p>
    <script type="text/javascript">alert("Hello World");</script>
</body>

If the alert works, you probably made a mistake including your Javascript file. If it does not work, something with your Javascript seems to bee wrong. Eg Javascript deactivated or Popup blocked.

也许您不小心阻止了警报在此水龙头中显示,请尝试关闭然后再次重新打开水龙头,同时检查浏览器中是否启用了 javascript。

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