三种方法
alert(); 最简单,将alert();括号内的内容弹出。
confirm(); 与alert();类似,包含确认和取消按钮,点击确定confirm();方法会返回true,点击取消confirm();方法会返回false;
prompt(); 与confirm();方法类似,点击时返回的事件相同。提供一个文本框,
alert();
alert("你喜欢前端工程师吗?");
效果如下:
confirm();
confirm("你喜欢前端工程师吗?");
效果如下:
prompt();
prompt("你喜欢前端工程师吗?");
confirm();例子
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>confirm</title>
<script type="text/javascript">
function rec(){
var mymessage=confirm("你是女士");
if(mymessage==true)
{
document.write("你是女士!");
}
else
{
document.write("你是男士!");
}
}
</script>
</head>
<body>
<input name="button" type="button" onClick="rec()" value="点击我,弹出确认对话框" />
</body>
</html>
prompt();例子
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>prompt</title>
<script type="text/javascript">
function rec(){
var score; //score变量,用来存储用户输入的成绩值。
score =prompt();
if(score>=90)
{
document.write("你很棒!");
}
else if(score>=75)
{
document.write("不错吆!");
}
else if(score>=60)
{
document.write("要加油!");
}
else
{
document.write("要努力了!");
}
}
</script>
</head>
<body>
<input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!" />
</body>
</html>