多个 OR 字符串 [英] Multiple OR Strings
本文介绍了多个 OR 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何在 If 语句中传递多个字符串.
I cannot find out how to pass multiple strings in an If statement.
这是我的代码:
var date = new Date();
if (document.getElementById("postcode-entry").value == ("G74" || "G75")) {
if (date.getHours() < 8 ) {
window.alert("Sorry we are not open at the moment, please try again later.");
} else {
window.open("http://http://stackoverflow.com");
}
} else {
window.alert("Sorry we do not Delivery to your area, please collect from store");
}
我该怎么做?
推荐答案
短语 ("G74" || "G75")
强制对每个字符串进行布尔计算,并且两者都将始终返回 true.
The phrase ("G74" || "G75")
forces a boolean evaluation on each string, and both will return true always.
所以你需要做这样的事情:
So you would need to do something like this:
var myvar = document.getElementById("postcode-entry").value;
if(myvar === "G74" || myvar === "G75")
这篇关于多个 OR 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文