javascript - 多个 OR 字符串

标签 javascript string if-statement return-value

我不知道如何在 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/

相关文章:

javascript - ASP.NET 中多个 JavaScript block 的性能影响?

python - 如果值已经是字符串,我应该避免转换为字符串吗?

javascript - 循环对象并根据选项选择将值显示到列表中

javascript - 在不同时区克隆日期对象是否会保留其原始时区?

javascript - Gulp 命令在记事本中打开 gulp.js 而不是运行它

javascript - CefSharp - 获取 AJAX 请求的结果

string - testLink 中的 "ghost string"是什么?幽灵字符串可选地在 testLink 中生成许多项目

ruby - 使用 JSON 字符串分配变量

c - 返回到 if 语句的开头

java - 问 : Rental Car Calculator | Use a sentinel value loop