<%@ page contentType="text/html; charset=GBK" language="java" errorPage=""%><html>
<head>
<script language="javascript">
function checkForm(form){
  if(isEmpty(form.uid.value) || isEmpty(form.password.value)) || 
  isEmpty(form.confirmPassword.value) || isEmpty(form.email.value) ||
  isEmpty(form.question.value) || isEmpty(form.answer.value)){
  alert("请将必填项填写完整!");
  return false;
  }
  if(form.password.value != form.confirmPassword.value){
  alert("两次密码不匹配!");
  return false;
  }
  if(form.password.value.length < 6 || form.password.value.length > 16){
  alert("密码长度不得少于6个字符,不得多于16个字符!");
  return false;
  }
  return true;
  }
  function isEmpty(str){
  if(str == null || str.length == 0)
  return true;
  else
  return false;
  }
</script>
<title>用户注册</title>
</head>
<body>
<form name="userRegisterForm" method="post" action="register.jsp" onsubmit="return checkForm(this);">

解决方案 »

  1.   

    function isEmpty(str){
      if(str == null || str.length == 0)
                            {
      return true;
                            }
      else
                            {
      return false;
                            }
      }
      

  2.   

    变量名尽量不要用保留字,像form等
      

  3.   

    if(isEmpty(form.uid.value) || isEmpty(form.password.value)) || isEmpty(form.confirmPassword.value) || isEmpty(form.email.value) || isEmpty(form.question.value) || isEmpty(form.answer.value))isEmpty(form.password.value))这边多了个")"改为
    if(isEmpty(form.uid.value) || isEmpty(form.password.value) || isEmpty(form.confirmPassword.value) || isEmpty(form.email.value) || isEmpty(form.question.value) || isEmpty(form.answer.value))
    就好了
      

  4.   

    试试<html>
    <head>
    <script language="javascript">
    function checkForm(form){
     if(isEmpty(form.uid.value) || isEmpty(form.password.value) || 
     isEmpty(form.confirmPassword.value) || isEmpty(form.email.value) ||
     isEmpty(form.question.value) || isEmpty(form.answer.value)){
     alert("请将必填项填写完整!");
     return false;
     }
     if(form.password.value != form.confirmPassword.value){
     alert("两次密码不匹配!");
     return false;
     }
     if(form.password.value.length < 6 || form.password.value.length > 16){
     alert("密码长度不得少于6个字符,不得多于16个字符!");
     return false;
     }
     return true;
     } function isEmpty(str){
     if(str == null || str.length == 0)
     return true;
     else
     return false;
     }
    </script>
    <title>用户注册</title>
    </head>
    <body>
    <form name="userRegisterForm" method="post" action="register.jsp" onsubmit="return checkForm(this);">
    </body>
    </html>