2 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
可以的,可以為任意類型。區(qū)別于c語(yǔ)言的只能使用int。
1 2 3 4 5 6 7 8 9 10 11 | 實(shí)例參考: var x="我"; switch(x) { case "你":alert("你");break; case "我":alert("我");break; case "他":alert("他");break; default:alert("誰?"); } 語(yǔ)法 switch(n){case 1: 執(zhí)行代碼塊 1 break;case 2: 執(zhí)行代碼塊 2 break;default: n 與 case 1 和 case 2 不同時(shí)執(zhí)行的代碼} |

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
可以,<html>
<head>
</head><script language="javascript">
function test(x){
switch(x)
{
case 'a':
alert("a");
break;
case 'b':
alert("b");
break;
case 3: ;
alert("c");
break;
default:
alert("default");
}
}
</script>
<body onload="test('b')">
</body>
</html>
添加回答
舉報(bào)