<script>
   function CheckForm(){
      var a=document.getElementsByTagName("input");
      for (var i=0;i<a.length;i++){
         if (a[i].type.toLowerCase()=="text"){
             if (a[i].value==""){
                  alert("有空值!");
                  a[i].focus();
                  return false;
              }
         }
      }
   }
</script>
<form method="POST" action="" onsubmit="return CheckForm();">
.................</form>

解决方案 »

  1.   

    <script>
       function CheckForm(){
          var a=document.getElementsByTagName("input");
          for (var i=0;i<a.length;i++){
             if (a[i].type.toLowerCase()=="text"){
                 if (a[i].value==""){
                      alert("不能是空值!");
                      a[i].focus();
                      return false;
                 }
                 if (!/^\d+$/g.test(a[i].value)){
                      alert("必须是非负整数!");
                      a[i].focus();
                      return false;
                 }
             }
          }
       return true;
       }
    </script>