我不知道如何在 If 语句中传递多个字符串。
这是我的代码:
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")
强制对每个字符串进行 bool 计算,并且两者都将始终返回 true。
所以你需要做这样的事情:
var myvar = document.getElementById("postcode-entry").value;
if(myvar === "G74" || myvar === "G75")
关于javascript - 多个 OR 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22656164/