js:三种弹出框(alter警告,confirm确认,prompt提示)
三种弹出框都属于window对象,完整写作window.alter,三种弹出框都可省略window.alter弹出警告框,只有一个确定按钮alert("这是一个警告框");confirm弹出确认框,有两个按钮:确定和取消,分别返回true和falseconfirm("这是一个确认框,确定返回true,取消返回false");prompt弹出提示框,确定,取消,输入框,确定返回输入框的值(不输入为空
·
三种弹出框都属于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>
更多推荐
已为社区贡献2条内容
所有评论(0)