語法格式

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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 hfnkiki 的頭像
    hfnkiki

    我要勇敢地追逐我的世界.我的夢...

    hfnkiki 發表在 痞客邦 留言(0) 人氣()