日期:2014-05-16  浏览次数:20348 次

菜鸟问题!用户名和密码登陆验证,进来瞅瞅呗~谢谢!
我自己用Eclipse写得用户名和密码登陆传参,自个加上得javascript验证.
帮忙看一下哪里写错了,为何javascript不起作用呢.谢谢!
欢迎批评,指正!


HTML code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Login.html</title>
    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
  <script language="javascript">
function validate(myform)(
    if(myform.userName.value.length==0){
        alert("请填写用户名!");
        myform.userName.focus();
        return false;
}
    if(myform.userPassword.value.length==0){
        alert("请填写密码!");
        myform.userPassword.focus();
        return false;
}
)
</script>
    <form method="post" action="/lesson4/servlet/login" name="login" onsubmit="return validate(this)">
    用户名:<input type="text" name="userName">
    密  码 :<input type="password" name="userPassword">
    <input type="submit" name="提交" value="提交"><input type="reset" name="重置" value="重置">
    </form>
  </body>
</html>




------解决方案--------------------
function validate(myform){ //这里
if(myform.userName.value.length==0){
alert("请填写用户名!");
myform.userName.focus();
return false;
}
if(myform.userPassword.value.length==0){
alert("请填写密码!");
myform.userPassword.focus();
return false;
}
} //这里
------解决方案--------------------
楼上正解, 函数应该是{},而你用了()