javascript使用消息框
之前很多地方都用过alert,它的作用是弹出一个警告框,我们调用的方法是alert("输入的内容");其实更正确的写法是 window.alert("输入的内容");其原因是window对象是顶层对象,位于顶层对象的下级可以直接调用,而不必再加window.
我们以一个例子来演示三种消息框:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type="text/javascript">
window.alert("点击确定");//警告对话框
var con = window.confirm("aaa");//确认对话框
if(con)
{
window.alert("thank you");
}
else
{
window.alert("bye");
}
var pro = window.prompt("欢迎,请输入一些东西");//提示消息框
</script>
</head>
<body>
</body>
</html>
我们在这里都加入了window,这样能加深对象接口的层次关系。
1.window.alert():警告对话框,是一个模态对话框,点击确定消失。
2.window.confirm():确认对话框,其返回值有true和false。
3.window.prompt ();提示框,用于输入一些信息。默认文本为ubdefined。
浙公网安备 33010602011771号