![](/img/trans.png)
[英]ReferenceError: document is not defined (JavaScript in VS Code)
[英]Atom: Javascript shows “ReferenceError: document is not defined” after putting code on body HTML
Javascript 腳本顯示:
ReferenceError:運行此代碼時未定義文檔
HTML 和 JS :
const button = document.querySelector('#click') button.addEventListener('click',()=>{ alert('clicked') })
<.DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>practice</title> </head> <body> <button type="button" id="click" name="button">click me</button> <script src="Pracitce.js" charset="utf-8"></script> </body> </html>
此外,當我在 Chrome 瀏覽器上運行HTML
時,單擊事件不會觸發任何內容。 如何將我的兩個文件合二為一? 將“腳本”與源代碼放在一起后有什么問題?
Your browser window
object has document property in it, you need to link your JS file with your HTML file and then run your HTML file and view the output in the browser.
您還可以在瀏覽器中使用console
來運行示例 JS 代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.