1. 程式人生 > >怎麼用javascript判斷文字框是否為空?

怎麼用javascript判斷文字框是否為空?

 <!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN"  
  "http://www.w3.org/TR/html4/loose.dtd">  
  <html>  
  <head>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <title>無標題文件</title>  
  </head>  
  <script   language="javascript">  
  <!--  
  function   isfull(){  
   
      if   (document.dd.username.value==""){  
      alert("使用者名稱不能為空");  
      document.dd.username.focus();  
      return   false;  
    }  
    if   (document.dd.password.value==""){  
      alert("密碼不能為空");  
      document.dd.password.focus();  
      return   false;  
  }  
  return   true;}  
  </script>  
  <body>  
  <form   name="dd"   method="post"   action=""   onSubmit="return   isfull();">  
      <input   type="text"   name="username">  
   
   
      <input   type="text"   name="password">  
      <input   type="submit"   name="Submit"   value="提交">  
  </form>  
  </body>  
  </html>