語法格式
switch()
{
case0:
break;
case1:
break;
case2:
break;
default;
}
<html>
<body>
<p id="demo">This is paragraph.</p>
<button type="button" onclick="myFunc()">
Push me!
</button>
<script>
function myFunc()
{
var x, y=4;
switch(y)
{
case 4:
x="A";
break;
case 3:
x="B";
break;
default:
x="C";
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
輸出結果為A
全站熱搜
留言列表