簡體   English   中英

原子:Javascript 在將代碼放在主體 HTML 后顯示“ReferenceError:文檔未定義”

[英]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 代碼。

您可以在此處了解有關document object 的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM