<script type="text/javascript">
function login() {
  if (trim(document.getElementById("username").value) == "") {
   alert("用户名不能为空!");
   document.getElementById("username").focus();
   return;
  } 
 
  if (trim(document.getElementById("password").value) == "") {
   alert("密码不能为空!");
   document.getElementById("password").focus();
   return;
  }
  with (document.getElementById("userForm")) {
   method = "post";
   action = "user/login.do?command=login";
   submit();
  }
 }
</script>
</head>
<body>
 <center>
 <h1>登陆</h1>
 <hr>
 <form name="userForm"  id="userForm">
  用户:<input type="text" name="username" id="username"><br>
  密码:<input type="password" name="password" id="password"><br>
  <input name="btnLog" type="button" id="btnLog" value="登陆" onclick="login()">
  <input type="reset" value="取消"><br>
  <a href=user/registerinput.do>还没用户名,注册一个吧!</a>
 </form>
 <p>
</center>
</body> 

解决方案 »

  1.   

    看起来是没问题的,在仔细检查检查,js有一个错误,就不会提交了,你可以把button改为submit,然后吧onclick的函数换成onsubmit,做个提交检测,试试又没问题
      

  2.   


     if (document.getElementById("username").value.trim() == "") { 
      alert("用户名不能为空!"); 
      document.getElementById("username").focus(); 
      return; 
      }   if (document.getElementById("password").value.trim() == "") { 
      alert("密码不能为空!"); 
      document.getElementById("password").focus(); 
      return; 
      } 
      

  3.   

    if (document.getElementById("username").value.trim() == "") {
    alert("用户名不能为空!");
    document.getElementById("username").focus();
    return;
    }if (document.getElementById("password").value.trim() == "") {
    alert("密码不能为空!");
    document.getElementById("password").focus();
    return;
    }
      

  4.   

    你的trim函数哪来的?js内置是没有trim函数的需要自己实现,是不是没有包含这个函数啊