javascript 如何合并多个案例?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14221778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:03:01  来源:igfitidea点击:

How Can I Combine Multiple Cases?

javascriptcase

提问by Rolf

Possible Duplicate:
JavaScript or-expression in a switch case

可能的重复:
切换案例中的 JavaScript 或表达式

case 'att':
   window.location.replace('/att-Forms.htm');
   break;
case 'at&t':
   window.location.replace('/att-Forms.htm');    
   break;

is there a way to shorten this with some kind of "or" function?

有没有办法用某种“或”函数来缩短它?

回答by epascarello

Combine the cases

结合案例

case 'att':
case 'at&t':
    window.location.replace('/att-Forms.htm');    
    break;

回答by VisioN

Just place casestatements one after another:

只需case一个接一个地放置语句:

case "att":
case "at&t":
    window.location.replace("/att-Forms.htm");
    break;