我有这个网址
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/