<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html140/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Sample Page!</title>
<script language="JavaScript" type="text/javascript">
<!--
var msg="\nswitch流程控制语句 : \n\n";
//响应按钮的onclick事件处理程序
function Test()
{
var year=window. prompt("请输入您的军龄(整数值,0表示未参军) : ",25);
var army;
switch(year)
{
case 0:
army="平民";
break;
case 1:
army="列兵";
break;
case 2:
army="上等兵";
break;
case 3:
case 4:
case 5:
army="一级士官";
break;
case 6:
case 7:
case 8:
army="二级士官";
break;
default:
if (year>8)
army="中高级士官";
}
//alert(year);
msg+="军龄 : "+year+"年\n";
msg+="结论 : "+army+"\n";
alert(msg);
}
-->
</script>
</head>
<body>
<center>
<form>
<input type=button value="测试" onClick="Test()">
</form>
</center>
</body>
</html>
本来按java的思想只要符合条件就会弹出对应的动作,可是这里除了输入8以上能有用,其他均为没找到?奇怪,不懂 |