<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to Daily News</title>
<script type="text/javascript" src="Scripts.js">
</script>
<link href="homepage.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="body">
<div class="header">
<a href="#" title="Home"><img id="header-image" src="news_logo.png" /></a>
<form id="login-form" action="customerLogin.html" method="post" onsubmit="return validate(this)">
<table>
<tr>
<td><label for="loginid">Login:</label></td>
<td id="login-form"><input id="login-boxes" type="text" id="loginid"></td>
<td><label for="pword">Password:</label></td>
<td id="login-form"><input id="login-boxes" type="password" id="pword"></td>
</tr>
<tr>
<td></td>
<td id="login-buttons"><input type="submit" value=" Sign In ">
<input type="reset" value="Clear form">
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
我的Javascript是:
function validate(loginForm)
{
var booValid = true;
var strErrorMessage = "";
var minLength=5;
var maxLength=10;
if(loginForm.pword.value.length < minLength)
{
strErrorMessage = "password must at least 5 characters\n";
booValid=false;
}
if(loginForm.pword.value.length > maxLength)
{
strErrorMessage = "pasword must not more than 10 characters\n";
booValid=false;
}
if(loginForm.loginid.value.indexOf("@") == -1)
{
strErrorMessage = "please enter an e-mail address as your login name\n";
booValid=false;
}
if(!booValid)
{
alert(strErrorMessage);
}
return booValid;
}
我无法弄清楚这段代码是什么,它似乎根本没有从javascript中读取。
我不知道为什么不这样做。我也试过只使用登录表单和javascript然后它工作,当我把所有东西放在一起然后它不起作用。
答案 0 :(得分:1)
id=
替换为class=
您想要使用id
name
<input id="login-boxes" type="text" id="loginid">
<input id="login-boxes" type="password" id="pword">
到
<input class="login-boxes" type="text" name="loginid">
<input class="login-boxes" type="password" name="pword">
答案 1 :(得分:0)
尝试改变:
<input id="login-boxes" type="password" id="pword">
要
<input id="login-boxes" type="password" name="pword">
和
<input id="login-boxes" type="password" id="pword">
到
<input id="login-boxes" type="password" name="pword">