当你需要测试 a or b 时,你会如何使用 switch
case
同样的情况?
switch (pageid) {
case "listing-page":
case "home-page":
alert("hello");
break;
case "details-page":
alert("goodbye");
break;
}
最佳答案
你可以使用fall-through:
switch (pageid)
{
case "listing-page":
case "home-page":
alert("hello");
break;
case "details-page":
alert("goodbye");
break;
}
关于javascript - 测试开关中的多个案例,例如 OR (||),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6513585/