(1)警告框
模态对话框,只有关闭了才能继续操作
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
alert("I am an alert box!");
}
</script>
</head>
<body>
<input type="button" οnclick="myFunction()" value="Show alert box">
</body>
</html>
(2)确认框
可以点击确定或取消。点击确定返回true,否则返回false
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display a confirm box.</p>
<button οnclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x;
var r=confirm("Press a button!");
if (r==true)
{
x="You pressed OK!";
}
else
{
x="You pressed Cancel!";
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
(3)提示框
1. 用于提示用户在进入页面前输入某个值
2.当提示框出现后,用户需要输入某个值,然后点击确认或取消才能继续操作
3.点击确认,返回输入的值;点击取消,返回null
<!DOCTYPE html>
<html>
<body>
<p>点击按钮查看输入的对话框。</p>
<button οnclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x;
var person=prompt("请输入你的名字","Harry Potter");
if (person!=null)
{
x="你好 " + person + "! 今天感觉如何?";
document.getElementById("demo").innerHTML=x;
}
}
</script>
</body>
</html>