<html>
<head>
<title>forms example</title>
</head><body>
<form action="welcome.php" method="post">
姓名:<input tpye="text" name="name"><br>
年龄:<input type="test" name="age"><br>
<input name="submit" type="submit" value="提交" />
<input type="reset" name="reset" value="重置" />
</body>
<html>如果name test为空,就弹出一个窗口(提示name 框为空),or age test 为空,也弹出一个窗口目前正在学PHP,请各位帮帮忙,不是我不google和百度,只是这种问题知道怎么用google找??

解决方案 »

  1.   


    <form>里加上onclick 变成 <form action="welcome.php" method="post" onsubmit="return check()">
    然后写个js方法:
    function check(){
       if(...){     //验证
          return true;
       }else{
          return false;
       }
    }
      

  2.   

    google 之后搞定了:<html>
    <head>
    <title>表单验证</title>
    </head><script   type="text/javascript">  
      function   checkInput()  
      {  
          var   name   =   document.form1.name.value;  
          var   age   =   document.form1.age.value;  
          if(name   ==   ""){  
              alert("用户不能为空!");  
              document.form1.name.focus();  
              return false;  
          }
      if(age   ==   ""){  
              alert("密码不能为空!");  
              document.form1.age.focus(); 
      return false;
          }  
          return true;  
      }  
      </script><body>
    <form name=form1 action="welcome.php" method="post" onsubmit="return checkInput()">
    姓名:<input tpye="text" name="name"><br>
    年龄:<input type="test" name="age"><br>
    <input type="submit" name="submit"  value="提交" />
    <input type="reset" name="reset" value="重置" />
    </form></body>
    <html>
    还是谢谢各位
      

  3.   

    <form onsubmit="check()"><script>
        function check(){
            if(document.getElementById("文本框id").value == ""){
                alert("不能为空");
            }
        }
    </script>
      

  4.   

    <form onsubmit="return(check())"><script>
        function check(){
            if(document.getElementById("文本框id").value == ""){
                alert("不能为空");
            }
        }
    </script>