JavaScript中的三种弹出框的区别与使用

JavaScript中有三种原生的弹出框,分别是alert、confirm、prompt。分别表示弹出框、确认框、信息框。

以下是示例代码:

<!DOCTYPE html>
<html>
<head>
<title>JavaScript中的三种弹出框</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head>
<body>
<input type="submit" value="alert" onclick="alertExample()" />
<input type="submit" value="confirm" onclick="confirmExample()" />
<input type="submit" value="prompt" onclick="promptExample()" />
</body>
<script type="text/JavaScript">
function alertExample(){
alert("这是弹出框");
} function confirmExample(){
var r=confirm("按下按钮");
if (r==true){
alert("您按了确认!");
}else if(r==false){
alert("您按了取消!");
}
} function promptExample() {
var score;//分数
var degree;//等级
score = prompt("你的分数是多少?");
if (score > 100){
degree = '耍我?100分满分!';
}else{
switch (parseInt(score / 10)) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
degree = "恭喜你,又挂了!";
break;
case 6:
degree = "勉强及格";
break;
case 7:
degree = "凑合,凑合"
break;
case 8:
degree = "不错,不错";
break;
case 9:
case 10:
degree = "高手高手,佩服佩服";
}
}
alert(degree);
}
</script>
</html>
上一篇:mssql数据库分页查询效率的一次体会


下一篇:java学习(二)