<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
function my()
{var myweek =document.getElementById("con").value;//myweek表示星期几变量
switch(myweek)
{
case a:
case b:
alert("学习理念知识");
break;
case c:
case d:
alert("到企业实践");
break;
case e:
alert("总结经验");
break;
default:
alert("周六、日休息和娱乐");
}
}
</script>
</head>
<body>周计划
<input type="text" id="con">
<input type="button" value="点击" onclick="my()">
</body>
</html>
var num = 25;
switch(true){
case num > 15 && num < 26:
alert(1);
break;
case num <= 15:
alert(2);
break;
default:
alert(3);
}
switch(num){
case 14:
alert(2);
break;
case 25:
alert(1);
break;
default:
alert(3);
}
这样的话你是否明白?
我忘记给字符串加引号了,谢谢
也可以是字符串