JavaScript-3
消息框:警告、确认、提示框
警告框:
alert(“文本”);
实例:
<html>
<head>
<script type="text/javascript">
function disp_alert(){
alert("我是警告框!!")
}
</script>
</head>
<body>
<input type="button" value="显示警告框" />
</body>
</html>
实图:
确认框:(点击确认返回true,点击取消返回false)
confirm(“文本”);
实例:
<html>
<head>
<script type="text/javascript">
function show_confirm(){
var r=confirm("请选择!");
if (r==true){
alert("你点击了确定!");
}
else{
alert("你点击了取消!");
}
}
</script>
</head>
<body>
<input type="button" value="显示确认框" />
</body>
</html>
实图:
提示框:输入某个值,点击确认返回输入值,点击取消返回null。
prompt(“文本”,”默认值”);
实例:
<html>
<head>
<script type="text/javascript">
function disp_prompt(){
var name=prompt("请输入您的名字","Michael")
if (name!=null && name!=""){
document.write("Hello!" + name )
}
}
</script>
</head>
<body>
<input type="button" value="显示提示框" />
</body>
</html>
实图:
转载于:https://blog.51cto.com/diesel/511981