【发布时间】:2019-09-20 09:22:02
【问题描述】:
如何在javascript中设置双重条件?
我的代码不起作用。使用正确的密码,window.location 不起作用
var attempt = 3; // Variable to count number of attempts.
// Below function Executes on click of login button.
function validate() {
var password = document.getElementById("password").value;
if (password == "ad" && event.keyCode === 13) {
window.location = "https://pac.com/arias"; // Redirecting to other page.
return false;
} else {
attempt--; // Decrementing by one.
alert("Contraseña incorrecta. Inténtalo de nuevo!");
// Disabling fields after 3 attempts.
if (attempt == 0) {
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
}
}
只有一个条件有效,但不是两个条件都有效...¿我做错了什么?
【问题讨论】:
-
... && event.keyCode === 13?什么活动?此外,从代码中的 URL 来看,这看起来可能是为了在公共站点上运行。请注意,就安全性而言,这几乎是最弱的。 -
另外请用HTML更新sn-p,保存前记得点击整理
-
它仅用于演示工作。我想php来处理真正的安全性。谢谢
-
另外如果你使用了提交事件,你不需要测试进入
标签: javascript logical-operators