五趾的鱼
2017-04-22 10:29
var my =70;
switch(my)
{
case my<60:
document.write("又是一周多会放假啊?");
break;
case 60<=my<=70 :
document.write("马上就放了 哈哈");
break;
case 100>my>70 :
document.write("嗯 过会放假");
break;
case 100<my :
document.write("放假了");
break;
default:
document.write("你是外星人哇");
}
下面是例子
<!DOCTYPE html>
<html>
<body>
<p>点击下面的按钮来显示今天是周几:</p>
<button onclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x;
var d=new Date().getDay();
switch (d)
{
case 0:
x="Today it's Sunday";
break;
case 1:
x="Today it's Monday";
break;
case 2:
x="Today it's Tuesday";
break;
case 3:
x="Today it's Wednesday";
break;
case 4:
x="Today it's Thursday";
break;
case 5:
x="Today it's Friday";
break;
case 6:
x="Today it's Saturday";
break;
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
你好,case后面只能跟 常量,如果判断表达式的话,用if条件语句
var my =110;
switch(true)
{
case my<6:
document.write("又是一周多会放假啊?");
break;
case 6<=my&&my<=7:
document.write("马上就放了 哈哈");
break;
case 10 >my&&my > 7 :
document.write("嗯 过会放假");
break;
case 10 <my&& my<15 :
document.write("放假了");
break;
default:
document.write("你是外星人哇");
}
不可能有switch(true)
有大神可以详细的解释一下么 true 的作用
switch(my)改成switch(true)
JavaScript进阶篇
468744 学习 · 22132 问题
相似问题