你的submit按钮没有和函数关联。
submit换成button,然后写onclick函数就可以了

解决方案 »

  1.   

    function check()
    {
     var nickName=window.document.form1.nickName.value;
     var pwd=window.document.form1.pwd.value;
     if(isEmpty(nickName))
     {
      alert("Input your name:");
      window.document.form1.nikeName.focus();
      return false;
     }
     if(isEmpty(pwd))
     {
      alert("Input your password:"); 
      window.document.form1.pwd.focus();
      return false;
     }
    return true
      

  2.   

    <script language="JavaScript">
    <!--
    function isEmpty(str)
    {
     if ((str==null)||(str.length==0))
     {
      return true;
     }
     else
     {
      return false;
     }
    }function check()
    {
     var nickName=document.form1.nickName.value;
     var pwd=document.form1.pwd.value;
     if(isEmpty(nickName))
     {
      alert("Input your name:");
      document.form1.nickName.focus();  return false;
     }
     if(isEmpty(pwd))
     {
      alert("Input your password:"); 
      document.form1.pwd.focus();  return false;
     }
     return true;
    }
    -->
    </script>
    <html>
    <body bgcolor="#FFFFFF" text="#000000">
     <div align="center">
     <form name="form1" method="post" action="test.jsp" onsubmit="return check()">
      <table width="350" border="0" cellspacing="0">
       <tr>
        <td width="108" bgcolor="#ffd6c8" height="27">
         <div aligh="right">Name:</div>
        </td>
        <td width="238" bgcolor="#ffd6c8" height="27">
         <input type="text" name="nickName" size="20" maxlength="10">
        </td>
       </tr>
       <tr>
        <td width="108" bgcolor="#ffd6c8" height="27">
         <div aligh="right" >Password:</div>
        </td>
        <td width="238" bgcolor="#ffd6c8" height="27">
         <input type="password" name="pwd" size="20" maxlength="10">
        </td>
       </tr>
       <tr>
         <td width="108" bgcolor="#ffd6c8">&nbsp;</td>
         <td width="238" bgcolor="#ffd6c8">
          <input type="submit" name="Submit" value="OK">
          <input type="reset"  name="reset"  value="Cancle">
         </td>
        </tr>
       </table>
     </form>
     </div>       
    </body>
    </html>
      

  3.   

    window.document.form1.nikeName.focus();
    -------->
    window.document.form1.nickName.focus();