<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
//获取月份
function getMonth(){
//获取对象
var inputObj = document.getElementById("month");
var months = inputObj.value;
switch(months){
case 1:
case 3:
case 5:
case 7:
case 8:
alert("该月份有31天");
break;
case 4:
case 6:
case 9:
case 11:
alert("该月份有30天");
break;
case 2:
alert("该月份有29天");
break;
}
}
</script>
</head>
<body>
<input type="text" id="month" value="" /><br />
<input type="button" onclick="getMonth()" value="一个好丑的按钮" />
</body>
</html>
switch语句没用 用if else语句就有用 求解 麻烦大家了
你这个代码,加你你还是截图吧,难看懂啊。。。
var months =parseInt( inputObj.value);
switch是===对比,不是==,===连类型一起判断,inputObj.value是字符串,case是数字,类型不一样所以一个没有匹配