当你需要测试 a or b 时,你会如何使用 switch
case
同样的情况?
How would you use a switch
case
when you need to test for a or b in the same case?
switch (pageid) {
case "listing-page" || "home-page":
alert("hello");
break;
case "details-page":
alert("goodbye");
break;
}
你可以使用fall-through:
You can use fall-through:
switch (pageid)
{
case "listing-page":
case "home-page":
alert("hello");
break;
case "details-page":
alert("goodbye");
break;
}
这篇关于测试开关中的多个案例,例如 OR (||)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!