1
我有一些簡單的東西。我有一個html文件和JavaScript文件。在JavaScript文件中調用簡單的alert()
函數,但它不起作用!JavaScript外部腳本alert()函數不起作用
我在JavaScript文件中寫了第二行以確保我沒有給出不正確的路徑console.log()
並且它按預期工作。
HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
</head>
<body>
<div id="container">
</div>
<script src="functionality.js"></script>
</body>
</html>
在外部JavaScript文件:
alert('hello'); // does not get executed
console.log('hello'); // gets executed
爲什麼這不起作用?
沒有明顯的原因,它不應該工作。控制檯中的任何消息?也許你在瀏覽器中禁止了警報? – mplungjan
使用Chrome?您最近是否按下了「防止此頁面創建額外的撥號」?嘗試重新啓動瀏覽器。 – Tholle
如果是這種情況@mplungjan說 - 那麼這可能會有所幫助 - http://stackoverflow.com/questions/19640361/re-enabling-window-alert-in-chrome – shershen