javascript简单判断表单(用户名密码是否为空,密码长度)

来源:互联网 发布:调查问卷数据 编辑:程序博客网 时间:2024/06/02 11:58

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>表单简单判断</title>
</head>

<body>
<form action="" method="post" name="form1" target="_blank" id="form1" onSubmit="return check_login()">
  <table width="30%" height="144" border="0" align="center">
    <tr>
      <td width="19%">用户名:</td>
      <td width="81%"><label for="username"></label>
      <input name="username" type="text" id="username" size="25" maxlength="30" /></td>
    </tr>
    <tr>
      <td>密码:</td>
      <td><label for="password"></label>
      <input name="password" type="password" id="password" size="25" maxlength="30" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="button" id="button" value="提交" />
      <input type="reset" name="button2" id="button2" value="重置" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
<script language="javascript">
function check_login()
{

 if(document.form1.username.value==''")/*document.表单名.文本域名.value==''"*/
 {
 alert("请检查用户名是否为空!");
 return false;
 }
 if(document.form1.password.value==''"){
 alert("请检查您的密码是否为空!");
 return false
 }
 if(document.form1.password.value.length<6){
   alert("您的密码长度小于6!");
   return false
 }

}
</script>
</html>