<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
var myweek =prompt("请输入今天是周几","");//myweek表示星期几变量
switch(myweek)
{
case 1:
case 2:
document.write("学习理念知识");
break;
case 3:
case 4:
document.write("到企业实践");
break;
case 5:
document.write("总结经验");
break;
default:
document.write("周六、日休息和娱乐");
}
</script>
</head>
<body>
</body>
</html>
prompt输出默认是string类型,而switch要输入的是number,所以还要把myweek转化为number类型,有一个方法是switch(+myweek),你可以试一下
prompt语句弹窗后,我输入数值1-5,也没用
没有匹配到值时执行default语句