1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>JavaScript中的三种弹出框</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 6 <script type="text/JavaScript"> 7 function alertExample(){ 8 alert("这是弹出框"); 9 } 10 11 function confirmExample(){ 12 var r=confirm("按下按钮"); 13 if (r==true){ 14 //document.write("您按了确认!"); 15 alert("您按了确认!"); 16 }else if(r==false){ 17 //document.write("您按了取消!"); 18 alert("您按了取消!"); 19 } 20 } 21 22 function promptExample() { 23 var score;//分数 24 var degree;//分数等级 25 score = prompt("你的分数是多少?"); 26 if (score > 100){ 27 degree = ‘耍我?100分满分!‘; 28 }else{ 29 switch (parseInt(score / 10)) { 30 case 0: 31 case 1: 32 case 2: 33 case 3: 34 case 4: 35 case 5: 36 degree = "恭喜你,又挂了!"; 37 break; 38 case 6: 39 degree = "勉强及格"; 40 break; 41 case 7: 42 degree = "凑合,凑合" 43 break; 44 case 8: 45 degree = "不错,不错"; 46 break; 47 case 9: 48 case 10: 49 degree = "高手高手,佩服佩服"; 50 } 51 } 52 alert(degree); 53 } 54 </script> 55 </head> 56 <body> 57 <input type="submit" value="alert" onclick="alertExample()" /> 58 <input type="submit" value="confirm" onclick="confirmExample()" /> 59 <input type="submit" value="prompt" onclick="promptExample()" /> 60 </body> 61 </html>
时间: 2024-10-13 02:16:31