错误代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
function b()
{
var myweek=prompt("今天星期几?","1");
switch(myweek)
{
case 1:
case 2:
document.write("学习理论知识");
break;
case 3:
case 4:
document.write("到企业去实践");
break;
case 5:
document.write("总结经验");
break;
case 6:
case 7:
document.write("休息娱乐");
break;
default:alert("不查就不查");
}
}
</script>
</head>
<body>
<input name="button" type="submit" value="查看今日任务" onclick="b()" />
</body>
</html>
正确代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
function b()
{
var myweek=prompt("今天星期几?","1");
switch(myweek)
{
case '1':
case '2':
document.write("学习理论知识");
break;
case '3':
case '4':
document.write("到企业去实践");
break;
case '5':
document.write("总结经验");
break;
case '6':
case '7':
document.write("休息娱乐");
break;
default:alert("不查就不查");
}
}
</script>
</head>
<body>
<input name="button" type="submit" value="查看今日任务" onclick="b()" />
</body>
</html>
下面代码就是比上面代码case值那里多了单引号的区别,请问case值那里什么时候要单引号什么时候不要?why?