JavaScript 使用switch语句进行多选项选择
function myTest(val) {
var answer = "";
switch (val) {
case 1:answer= "alpha";
break;
case 2:answer = "beta";
break;
case 3:answer="gamma";
break;
case 4:answer = "delta";
break;
}
return answer;
}
myTest(2);
function myTest(val) {
var answer = "";
switch (val) {
case 'a':answer="apple";
break;
case 'b':answer="bird";
break;
case 'c':answer="cat";
break;
default:answer="stuff";
}
return answer;
}
myTest('a');