You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

密码验证跳转异常:输入不同密码均跳转到同一页面

密码验证跳转问题的解决方案

问题出在else if的条件判断里:你使用了赋值运算符=,而不是用来做比较的相等运算符==或严格相等运算符===。

当你写ff = tanishq1e02时,这不是在判断两者是否相等,而是把tanishq1e02的值赋给了ff,这个赋值操作的返回值就是被赋的字符串本身,在布尔逻辑里会被判定为true。所以不管你输入的是tanishq1e01还是其他值,都会进入这个else if分支,跳转到对应的页面。

修正后的代码如下:

var ff;
const tanishq1e01 = "tanishq1e01";
const tanishq1e02 = "tanishq1e02";
ff = prompt("Enter Given Password By Prattay: ");
if (ff === tanishq1e01) {
  window.location.href = "suppstsasd/tanishq1e01suppasd.html";
} else if (ff === tanishq1e02) {
  window.location.href = "suppstsasd/tanishq1e02suppasd.html";
} else {
  confirm("Not Right Password! Refreshing...");
  window.location.reload();
}

额外建议:

  • 使用const声明不会被修改的密码变量,比let更贴合语义
  • 优先用严格相等===判断,避免隐式类型转换带来的潜在问题

内容的提问来源于stack exchange,提问作者WTG MC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 13:01:05