這是HTML代碼:無法弄清楚什麼是錯我的JavaScript代碼
<form action="">
<div data-role="fieldcontain">
<label for="username">
Username
</label>
<input class="usernamevalidation validate" name="username" id="username" placeholder="" value="" type="text" maxlength="20" required>
</div>
<div data-role="fieldcontain">
<label for="password">
Password
</label>
<input class="validate" name="password" id="password" placeholder="" value="" type="password" maxlength="20" required>
</div>
<input id="submitLogin" type="submit" value="Log In" data-transition="slide">
<div id="errormsg"></div>
</form>
這是JavaScript代碼。當用戶名和密碼是「abc」時,我試圖對頁面進行硬編碼登錄。
username_test = document.getElementById("username").getAttribute("value") === "abc";
password_test = document.getElementById("password").getAttribute("value") === "abc";
if_true = window.location.href("Main_Menu.html");
if_false = document.getElementById("errormsg").innerHTML("<p style="color=red;">Invalid credentials.</p>");
function login() {
if (username_test && password_test)
{
if_true
}
else
{
if_false
}
}
您還沒有解釋什麼代碼是應該做的,什麼它目前確實。提示:[學習如何](http://www.creativebloq.com/javascript/javascript-debugging-beginners-3122820)[** debug ** JavaScript](https://developers.google.com/chrome-developer -tools /文檔/ JavaScript的調試)。 –