js:三种弹出框(alter警告,confirm确认,prompt提示)
https://blog.csdn.net/qq_52824207/article/details/124081188
三种弹出框都属于window对象,完整写作window.alter,三种弹出框都可省略window.
alter弹出警告框,只有一个确定按钮
alert("这是一个警告框");
confirm弹出确认框,有两个按钮:确定和取消,分别返回true和false
confirm("这是一个确认框,确定返回true,取消返回false");
prompt弹出提示框,确定,取消,输入框,确定返回输入框的值(不输入为空""),取消返回Null
prompt("这是一个提示框,确定返回输入值,取消返回Null","输入框内默认文本");
完整测试代码
- <!DOCTYPE html>
- <html>
- <head>
- <title>弹出框测试</title>
- </head>
- <body style="text-align: center;">
- <h1>弹出框测试</h1>
- <button onclick="test_1()">警告框</button>
- <button onclick="test_2()">确认框</button>
- <button onclick="test_3()">提示框</button>
- <p id="demo"></p>
- </body>
- <script>
-
- function test_1(){
- alert(("这是一个警告框"));
- }
-
- function test_2(){
- test2 = confirm("这是一个确认框,确定返回true,取消返回false");
- document.getElementById("demo").innerHTML = test2;
- }
-
- function test_3(){
- var test3 = prompt("这是一个提示框,确定返回输入值,取消返回Null","输入框内默认文本");
- document.getElementById("demo").innerHTML = test3;
- }
-
- </script>
- </html>
标签:返回,prompt,confirm,js,弹出,警告,alter
From: https://www.cnblogs.com/sunny3158/p/17270140.html