<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
function a1(){
var abc=prompt("今天是星期几","123");
switch(abc);
{
case 1:
case 2:
document.write("学习理念知识");
break;
case 3:
case 4:
document.write("到企业实践");
break;
case 5:
document.write("总结经验");
case 6:
case 7:
document.write("周六、日休息和娱乐");
break;
default:
alert("输入不对啊");
}}
</script>
</head>
<body>
<input type="button" value="做犀利" onClick="a1()">
</body>
</html>
switch(abc);
这里多了分号,删去
case 5: document.write("总结经验");
这里漏了break;
alert("输入不对啊");
这里分号敲成了中文分号,改成英文的即可
alert("输入不对啊");
var abc=prompt("今天是星期几","123");
这里接收的是字符型,转换一下数据类型吧
var abc=parseInt(prompt("今天是星期几","123"));
修改后的代码
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>switch</title> <script type="text/JavaScript"> function a1(){ var abc=parseInt(prompt("今天是星期几","123")); switch(abc) { 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" value="做犀利" onClick="a1()"> </body> </html>