【发布时间】:2021-05-16 15:54:22
【问题描述】:
我正在尝试获取当前页面的 loacation.pathname 并比较它以查看它的 /Login 或 /Register,如果它是其中之一,则不应执行 if 中的代码。
代码:
if (location.pathname != '/Login' || location.pathname != '/Register')
{
prevView.push(location.href); // Add View to PreviousView so when needed we can navigate back to previous Page/View
prevView.shift(); // Remove the First element from the array
}
我也试过了:
if ((location.pathname != '/Login') || (location.pathname != '/Register')
和
if (((location.pathname != '/Login') || (location.pathname != '/Register')))
但不工作 - 我做错了什么。
【问题讨论】:
-
查看布尔逻辑。你需要
&&,而不是||。 -
您能否通过登录控制台检查 location.pathname 的值?
标签: javascript if-statement compare