2013-06-02 61 views
0

我試圖執行這個簡單的代碼,但我無法這樣做。我在這裏附上了它。我只需要用選定的密碼列出兩個用戶名。我認爲我處於正確的軌道上,但仍需要一些幫助。我知道這不是在腳本中對其進行硬編碼的可接受方法,但它是用於分配的。由於腳本文件中登錄頁面的問題

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>Login Page</title> 

<!--[if lt IE 9]> 
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 
</head> 
<body> 
<!-- login.html --> 
<form action="" method="post" id="loginForm"> 

<fieldset> 

    <legend>Login</legend> 

    <div><label for="email">Email Address</label> 
     <input type="email" name="email" 
     id="email" required></div> 
    <div><label for="password">Password</label> 
     <input type="password" name="password" 
     id="password" required></div> 

    <div><label for="submit"></label><input type="submit" 
     value=Login &rarr;" id="submit"></div> 
</fieldset> 
</form> 
<script src="js/login.js"></script> 
</body> 
</html> 

function titanValidateForm() { 
'use strict'; 
//Get references to the form elements: 
var email = document.getElementById(); 
var password = document.getElementById(); 

//validate credentials 

if((email == "[email protected]") && (password == "LogMeIn")) { 

    return true; 

    } 

else if ((email == "[email protected]") && (password == "hello1324")) { 

    return true; 

    } 

else { 
     alert('Please enter a valid email and/or password'); 

    return false; 

    } 
} 
//add window.onload to call the function && add an event listner. 

function init() { 
'use strict'; 

//confirm that document.getElementById() can be used: 

document.getElementById('loginForm').onsubmit = process; 

    } 
} //this ends init function 

window.onload = init; 
+6

你不能這樣做在客戶端用戶/密碼登錄(人獲得該文件發送到他們的電腦,他們會打開它並看到密碼/用戶名)。另外我想你的意思是將'.onsubmit'設置爲'titanValidateForm'而不是'process' –

回答

1
var email = document.getElementById(); 
var password = document.getElementById(); 

把你的元素的ID

var email = document.getElementById('email'); 
var password = document.getElementById('password');