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');

posted on 2018-04-08 20:42  HopeWu  阅读(538)  评论(0编辑  收藏  举报

导航