JavaScript中弹出警报对话框或者确认对话框
JavaScript通过使用弹出框或者对话框向用户提供拾取用户输入或者少量文本的功能。
警报对话框
将少量文本输出定向到浏览器窗口的最简单方法是使用警报框。
语法
alert("<message>");
例子
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function popup() {
alert("点击了按钮");
}
</script>
</head>
<body>
<input type="button" onclick="popup()" value="点击"
</body>
</html>
确认对话框
顾名思义,确认对话框用作确认用户操作的技术。
语法
confirm("<message>");
例子
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>确认对话框示例</title>
<button onclick="myFunction()">CLICK</button>
<script type="text/javascript">
function myFunction()
{
var a;
var b = confirm("是否进行下一步");
if (b == true) {
a = "你选择了确定";
}
else {
a = "你选择了取消";
}
document.getElementById("VAR").innerHTML = a;
}
</script>
</head>
</html>
日期:2020-04-11 23:04:37 来源:oir作者:oir
