刚刚学的javascrip,练练手,写了个小程序,用来查询每月的天数,主要运用的是switch方法
代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>查询每月的天数</title>
<script type="text/javascript">
function showDay()
{
var inputObj = document.getElementById("month");
var a = inputObj.value;
var b = parseInt(a);
switch(b)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
alert("本月是31天!");
break;
case 4:
case 6:
case 9:
case 11:
alert("本月是30天!");
break;
case 2:
alert("本月是29天!");
break;
default:
alert("你没有此月份!");
break;
}
}
</script>
</head>
<body>
月份:<input id="month" type="text"/>
<input type="button" value="查询" οnclick="showDay()"/>
</body>
</html>