javascript 当页面等于 X 时,逻辑运算符不起作用
javascript Logical Operators don't do function when page equals to X
我不想在 pageAge 或 pageMore 上执行 if 语句。当我转到 pageAge 时,它不会执行脚本,但是当我转到 pageMore 时,它会执行。我不确定在这种情况下使用哪个运算符。当我将 pageMore 放在 ||
之前时,它在那个页面上有效,但在另一个页面上无效。
if ( top.location.pathname != pageAge || pageMore) {
//if not verified go to connect
$("body").css("display", "none");
if (age === null && top.location.pathname != pageConnect) {
window.location.href = pageConnect;
}
//if to young go to age page while cookie is found (1day)
if (age == toYoung) {
window.location.href = pageAge;
}
//if already verified go to like page.
if (age == legal && top.location.pathname === pageConnect) {
window.location.href = pageLike;
}
}
应该是:
if ( top.location.pathname != pageAge && top.location.pathname != pageMore)
我不想在 pageAge 或 pageMore 上执行 if 语句。当我转到 pageAge 时,它不会执行脚本,但是当我转到 pageMore 时,它会执行。我不确定在这种情况下使用哪个运算符。当我将 pageMore 放在 ||
之前时,它在那个页面上有效,但在另一个页面上无效。
if ( top.location.pathname != pageAge || pageMore) {
//if not verified go to connect
$("body").css("display", "none");
if (age === null && top.location.pathname != pageConnect) {
window.location.href = pageConnect;
}
//if to young go to age page while cookie is found (1day)
if (age == toYoung) {
window.location.href = pageAge;
}
//if already verified go to like page.
if (age == legal && top.location.pathname === pageConnect) {
window.location.href = pageLike;
}
}
应该是:
if ( top.location.pathname != pageAge && top.location.pathname != pageMore)