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 == "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;
4

1 回答 1

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

放入元素的 id

var email = document.getElementById('email');
var password = document.getElementById('password');
于 2013-06-02T18:40:22.293 回答