switch语句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 错误代码: <!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? |