新手关于.js文件与html页分离的问题
我用javascript来检测提表单的正确与否,如果我把javascript的内容插入html页内,则可能成功运行检测,但是如果我把javascrip内容分开单独成为一个js文件,但却不能运行检测,请高手指教。
我的html内容如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> Insert title here </title>
<script language= "javascript " type= "text/javascript " src= "resource/checkForm.js "> </script>
</head>
<body>
<img alig= "center " src= "images/tree.jpg " width= "776 " height= "401 ">
<form name= "form1 " method= "post " action= " " onsubmit= "return check() ">
<table align= "center " width= "500 " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td width= "250 " align= "right "> <label> 用户: </label> </td>
<td width= "249 ">
<input type= "text " name= "accountname ">
</td>
</tr>
<tr>
<td align= "right "> 密码: </td>
<td>
<input type= "text " name= "password ">
</td>
</tr>
<tr>
<td align= "right ">
<input type= "submit " name= "Submit " value= "登陆 "> </td>
<td> <input type= "reset " name= "reset " value= "重写 "> </td>
</tr>
</table>
<label> </label>
</form>
</body>
</html>
js文件内容如下:
// JavaScript Document
function trim(s)
{
s=s.replace(/^ */, " ");
s=s.replace(/ *$/, " ");
return s;
}
function check()
{
if(trim(document.form1.accountname.value)== " ")
{
alert( "账户名不能为空 ");
document.form1.accountname.focus();
return false;
}
if(trim(document.form1.password.value)== " ")
{
alert( "密码不能为空 ");
document.form1.passw