本文介绍了if语句中多个OR表达式的简写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有以下简写 -
Is there a shorthand for the following -
if(tld == "com" || tld == "net" || tld == "co" || tld == "org" || tld == "info" || tld == "biz")
{
//do something;
}
推荐答案
你可以使用数组
if(["","com","net","co","org","info","biz"].indexOf(tld) > -1) {
// do something
}
或者如果您使用的是jquery:
or if you are using jquery :
$.inArray(tld, ["com","net","co","org","info","biz"])
REF -
这篇关于if语句中多个OR表达式的简写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!