執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
轉到 Spaces
<!DOCTYPE html> <html> <body> <h1>The Document Object</h1> <h2>The hasFocus() Method</h2> <p>Click inside this document to get focus.<br> Click outside this document to lose focus.</p> <p id="demo"></p> <script> setInterval("myFunction()", 1); function myFunction() { let text; if (document.hasFocus()) { text = "The document has focus."; } else { text = "The document does NOT have focus."; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>