<!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 就正常
prompt 输出的内容为string类型, 6为number类型,'6'为string类型,所以需要用case '6'