<html>   
    
  <head>   
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">   
  <title>New   Page   1</title>   
  <script   language="javascript">   
  function emptyalert()
{
if (trim(window.loginform.username.value)==""){
alert('请输入用户名!');

return false;

}
   if (trim(window.loginform.password.value)==""){
alert('请输入密码!');

return false;
}
}
    
  </script>   
  </head>   
    
  <body> 
<form name="loginform" method="post" action="" onSubmit="return emptyalert();"> <table width="350" height="126" border="0">
    <tr>
      <td width="56"> <strong> 用户名</strong></td>
      <td width="284"><input name="username" type="text" id="username"></td>
    </tr>
    <tr>
      <td><strong>密码</strong></td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr>
      <td colspan="2"><center><input type="submit" name="submit" value="提交">&nbsp;&nbsp;&nbsp;&nbsp;
         <input name="reset1" type="reset" id="reset1" value="取消"></center></td>
    </tr>
  </table>
  </body>         
          
  </html>

解决方案 »

  1.   

    修改后如下:
    <html>   
        
      <head>   
      <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">   
      <title>New   Page   1</title>   
      <script   language="javascript">   
      function emptyalert()
    {
    if (window.loginform.username.value==""){
    alert('请输入用户名!');

    return false;

    }
       if (window.loginform.password.value==""){
    alert('请输入密码!');

    return false;
    }
    }
        
      </script>   
      </head>   
        
      <body> 
    <form name="loginform" method="post" action="" onSubmit="return emptyalert();">
    <table width="350" height="126" border="0">
        <tr>
          <td width="56"> <strong> 用户名</strong></td>
          <td width="284"><input name="username" type="text" id="username"></td>
        </tr>
        <tr>
          <td><strong>密码</strong></td>
          <td><input name="password" type="password" id="password"></td>
        </tr>
        <tr>
          <td colspan="2"><center><input type="submit" name="submit" value="提交">&nbsp;&nbsp;&nbsp;&nbsp;
             <input name="reset1" type="reset" id="reset1" value="取消"></center></td>
        </tr>
      </table>
      </form>
      </body>         
              
      </html>
      

  2.   

    You should add "  </form>"tab,now you should have mind of form and button action 's difference.