源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> </head> <body> <h1>我的第一個 JavaScript </h1> <p id="demo"> JavaScript 可以觸發事件,就像按鈕點擊。</p> <script> function myFunction() { document.getElementById("demo").innerHTML="Hello JavaScript!"; } </script> <button type="button" onclick="myFunction()">點我</button> </body> </html>
運行結果