是否有以下简写 -
if(tld == "com" || tld == "net" || tld == "co" || tld == "org" || tld == "info" || tld == "biz")
{
//do something;
}
Run Code Online (Sandbox Code Playgroud) 假设您要检查用户在表单字段中输入的输入字符串.对于可能的值列表,哪一个是检查此输入的最快方法?
以下示例使用jQuery.
第一种方法:使用 ||
if (input == "firstValue" || input == "secondValue" || ... ) {
...
}
Run Code Online (Sandbox Code Playgroud)
第二种方法:使用 inArray()
if ($.inArray(input, array) >= 0) {
...
}
Run Code Online (Sandbox Code Playgroud)
这两种方法之间是否存在显着差异?