W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript Prompt</h1> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var txt; var person = prompt("请输入您的名字:", "哈利波特"); if (person == null || person == "") { txt = "用户取消输入"; } else { txt = "你好," + person + "!今天过得好吗?"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>