我的Javascript不执行,有谁知道为什么?

问题描述:

你能帮我用这段代码吗?我的Javascript不执行,有谁知道为什么?

<!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

是的,我想是的,但我不能改变,因为我已经在User455892上打勾了。 – James1 2010-09-27 05:26:14

+0

我不介意,我知道阿曼多,他的概率也不在乎。不过,你应该能够取消选中。要记住的重要一点是学习何时使用“名称”,“班级”和“身份证” – vol7ron 2010-09-27 15:48:12

  1. 你可能想用class=
  2. 而不是取代每id=你以后的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"> 
    

尝试改变:

<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">