代码示例:(标识:eg_js_prompt)
<!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>
运行结果: