switch中case 6 的case "6"
<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>switch</title>
<script?type="text/JavaScript">
function?jump(){
????var?myweek?=?prompt("今天星期幾?");
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?type="button"?onclick="jump()"?value="點點看">
</body>
</html>迷了
switch中case 6 的case "6"
那個算數字和字符串
prompt 彈出的輸入 6 異常顯示default
輸入加引號的3 就正常
2015-07-31
prompt 輸出的內容為string類型, 6為number類型,'6'為string類型,所以需要用case '6'