是否有以下的简写 -
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:
$.inArray(tld, ["com","net","co","org","info","biz"])
关于javascript - if 语句中多个 OR 表达式的简写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11127753/