跪求高手帮忙,做了个登录界面,想在提交表单前检测帐号和密码是否为空,但一按按钮就提交了,应该怎样去修改啊?
小弟javascript新手,请说得简单下!谢谢!
下面是主要的代码:
</style>
<script language="javascript">function check(){
var no=document.login-form.no.value;
var password=document.login-form.password.value;
if(no==""){
alert("帐号不能为空");
document.login-form.elements(0).focus();
return false;
}
if(password==""){
alert("密码不能为空");
document.login-form.elements(1).focus();
return false;
}
document.login-form.submit();
}
</script> 
  <form name="login-form" method="post" action="login" onSubmit="return check();" onReset="resetForm()"><td align="left"><input type="text" name="no" ></td><td width="50%" height="40" align="left"><input type="password" name="password"></td><td width="50%" height="40" align="right"><font size="+1" face="黑体">密码:&nbsp;&nbsp;</font></td><td width="50%" height="40" align="left"><input type="password" name="password"></td>
</tr>
<tr><td width="50%" height="40" align="right"><input name="按钮"  type="button" onclick="check()"  value="登录">
&nbsp;</td>
<td width="50%" height="40" align="left">&nbsp;<input name="重置" type="reset" value="重置"></td>
</tr>

解决方案 »

  1.   


    <script language="javascript">function check(){
    var no=document.loginform.no.value;
    var passwords=document.loginform.passwords.value;
    if(no==""){
    alert("帐号不能为空");
    document.loginform.elements(0).focus();
    return false;
    }
    if(passwords==""){
    alert("密码不能为空");
    document.loginform.elements(1).focus();
    return false;
    }
    document.loginform.submit();
    }
    </script> 
      <form name="loginform" method="post" action="login" onSubmit="return check();" onReset="resetForm()"><td align="left"><input type="text" name="no" ></td><td width="50%" height="40" align="left"><input type="password" name="passwords"></td>注意命名