源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> </head> <body> <p>點擊按鈕查看輸入的對話框。</p> <button onclick="myFunction()">點我</button> <p id="demo"></p> <script> function myFunction(){ var x; var person=prompt("請輸入你的名字","Harry Potter"); if (person!=null && person!=""){ x="你好 " + person + "! 今天感覺如何?"; document.getElementById("demo").innerHTML=x; } } </script> </body> </html>
運行結果