javascript - url参数及具体条件

标签 javascript

我有这个网址

http://www.example.com/ln-en/Category/Product/Product-A/Details

如果我使用这个if条件

(window.location.href.split("/")[6] !== "Product-A" || window.location.href.split("/")[6] !== "Product-B" || window.location.href.split("/")[6] !== "Product-C" || window.location.href.split("/")[6] !== "Intro" || window.location.href.split("/")[6] !== "vol-A-Free" || window.location.href.split("/")[6] !== "vol-B")

我得到结果true

但是如果我只使用这个

window.location.href.split("/")[6] !== "Product-A"

我收回false,这也是我期望给出的第一个条件。可能出了什么问题?

最佳答案

window.location.href.split("/")[6]“Product-A”

因此:

window.location.href.split("/")[6] !== "Product-A"false

window.location.href.split("/")[6] !== "Product-B"true

window.location.href.split("/")[6] !== "Product-"A" || window.location.href.split("/")[6] !== "Product-B" 

相同
false || true

这是true

您可能想在测试中使用 && 条件。

关于javascript - url参数及具体条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33937713/

相关文章:

javascript - HTML 图像翻转 : fade in to the left or right

javascript - 调用父类(super class)方法的更好方法

javascript - 无限滚动-圆柱页面(css/js)

JavaScript 初学者 : What is the functional difference between coding separate space character in functions etc

javascript - 在 Highcharts 中显示不可见系列的工具提示

javascript - 从 iFrame 中获取 BoundingClientRect

javascript - 获取鼠标位置并设置父div滚动的位置

javascript - Chrome 扩展、内容脚本和 XSS 攻击

javascript - 自引用 Parse.com 类

javascript - 未捕获的类型错误 : Illegal invocation error while sending data from ajax