-1
我已將此登錄表單與Javascript憑證驗證程序拼湊在一起。爲了測試驗證,我已將登錄名設置爲Ryan作爲用戶名,ryan1234作爲密碼。當證書有效時,用戶應該被重定向到Facebook。但是,它不工作。憑據驗證正確,但window.location屬性發送到一個損壞的位置?有效的登錄將不會打開鏈接
var modal = document.getElementById('id01');
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
var attempt = 3;
function validate() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == "Ryan" && password == "ryan1234") {
alert("Login successfully");
window.location = "https://www.facebook.com/"; // Redirecting to other page.
return false;
} else {
attempt--; // Decrementing by one.
alert("You have left " + attempt + " attempt;");
// Disabling fields after 3 attempts.
if (attempt == 0) {
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
}
}
<div id="id01" class="modal">
<form class="modal-content animate" action="action_page.php">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<img src="img_avatar2.png" alt="Avatar" class="avatar">
</div>
<div class="container-modal">
<label><b>Username</b>
</label>
<input type="text" placeholder="Enter Username" name="uname" id="username" required>
<label><b>Password</b>
</label>
<input type="password" placeholder="Enter Password" name="psw" id="password" required>
<button type="submit">Login</button>
<input type="checkbox" checked="checked">Remember me
</div>
<div class="container-modal" style="background-color:#f1f1f1">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
<span class="psw">Forgot <a href="#">password?</a></span>
</div>
</form>
</div>
</div>
這是有道理的,但它不成功,這導致我相信這是Codepen的問題,這是我建立它的地方,而不是你的更正。你知道我可以在哪裏測試這個代碼嗎? – RhinoTekMN
也許是一臺虛擬機(嘗試在本地託管一個虛擬網絡服務器),或者你可以嘗試一個免費的託管網站。這些將是我最好的猜測(除非你有自己的域名,那麼這將是一個很好的選擇)。請記住:Google是你的朋友...... – RasmusLD