Heim > Fragen und Antworten > Hauptteil
<!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("what is the day today?");//myweek表示星期几变量 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(" 有问题哦\n"); } } </script> </head> <body> <input type="button" value="这里" onClick="b()"> </body> </html>
巴扎黑2016-12-21 15:44:20
宝贝,你的Case6,case7后面不是冒号哦。肯定无法执行啊,自己细心一点。还有你传到函数里的是字符串,得转换成Int,像这样:parseInt(myweek),才可以哦