<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
var myweek = prompt("请输入今天是周几?");
switch(myweek)
{
case 1:
case 2:
case 3:
document.write("在家吃饭");
break;
case 4:
document.write("在外面吃饭");
break;
case 5:
document.write("在家吃饭");
break;
case 6:
case 7:
document.write("在外面吃饭");
break;
default:
document.write("请输入正确日期");
}
</script>
</head>
<body>
</body>
</html>
这代码输入1时怎么不执行case1 而执行default语句 输入其他的数值也是执行default
提示输入的应该是字符常量(把“1”当做字符了),转换为数字常量试试,switch(parseInt(myweek))
或者把 case 1:
改为: case "1":