脚本文件中登录页面的问题

时间:2013-06-02 18:35:45

标签: javascript html

我正在尝试执行这个简单的代码,但我无法这样做。我把它放在这里。我只需要用选定的密码列出两个用户名。我想我走在正确的轨道上,但仍然需要一些帮助。我知道这不是一个可以接受的方法,在脚本中硬编码,但这是一个任务。感谢

<!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 == "admin@titanmusicstore.com") && (password == "LogMeIn")) {

    return true;

    }

else if ((email == "enter@titanmusicstore.com") && (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;

1 个答案:

答案 0 :(得分:1)

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

输入元素的ID

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