<!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=gb2312" /> <title>无标题文档</title> <script> function checkIP() { var strIP=document.getElementById('iptext').value //对ip进行检验 strIP = strIP.replace(/\s/gi,"") //用空值替换空格 if (strIP==""){ alert("ip不能为空"); return; } var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g //匹配IP地址的正则表达式 if(re.test(strIP)) { if( RegExp.$1 <256 && RegExp.$2 <256 && RegExp.$3 <256 && RegExp.$4 <256) document.addIP.submit(); } alert("请输入正确的ip"); return; } </script> </head> <body> <form name="addIP" action="ViewaddServlet" method="post" id="addIP"> <input type="hidden" name="opflag" value="add"/> <input type="text" name="iptext" id="iptext" /> <input type="button" name="sumbit" value="提交" onclick="checkIP()"/> </form> </body> </html>
晕,刚才结贴太早了,
检验可以了,但是却没跳到ViewaddServlet里继续执行,
是因为表单未提交吗?

解决方案 »

  1.   

    js:document.getElementById('yourformid').submit();
      

  2.   


    <!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=gb2312" />
    <title>无标题文档</title>
    <script>
    function checkIP() 
    {  
    var strIP=document.getElementById('iptext').value 
    //对ip进行检验    
    strIP = strIP.replace(/\s/gi,"") 
    //用空值替换空格 
    if (strIP==""){ 
          alert("ip不能为空"); 
      return false; 

    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g        //匹配IP地址的正则表达式 
    if(re.test(strIP)) 

    if( RegExp.$1 <256 && RegExp.$2 <256 && RegExp.$3 <256 && RegExp.$4 <256) 
      return true; 

    alert("请输入正确的ip"); 
    return false;              
          

    </script>
    </head>再贴一次代码
      

  3.   


    <!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=gb2312" />
    <title>无标题文档</title>
    <script>
    function checkIP() 
    {  
    var strIP=document.getElementById('iptext').value 
    //对ip进行检验    
    strIP = strIP.replace(/\s/gi,"") 
    //用空值替换空格 
    if (strIP==""){ 
          alert("ip不能为空"); 
      return; 

    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g        //匹配IP地址的正则表达式 
    if(re.test(strIP)) 

    if( RegExp.$1 <256 && RegExp.$2 <256 && RegExp.$3 <256 && RegExp.$4 <256) 
      document.addIP.submit();

    alert("请输入正确的ip"); 
    return;              
          

    </script>
    </head><body>
    <form name="addIP"  action="ViewaddServlet" method="post" id="addIP"> 
        <input type="hidden" name="opflag" value="add"/>   
      <input type="text" name="iptext" id="iptext" /> 
      <input type="button" name="sumbit" value="提交" onclick="checkIP()"/>  
    </form>  
    </body>
    </html>刚才贴少了一部分
      

  4.   

    稍微改了一下<!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=gb2312" />
    <title>无标题文档</title>
    <script>
    function checkIP() 
    {  
    var strIP=document.getElementById('iptext').value 
    //对ip进行检验    
    strIP = strIP.replace(/\s/gi,"") 
    //用空值替换空格 
    if (strIP==""){ 
          alert("ip不能为空"); 
      return; 

    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g        //匹配IP地址的正则表达式 
    if(re.test(strIP)) 

    if( RegExp.$1 <256 && RegExp.$2 <256 && RegExp.$3 <256 && RegExp.$4 <256){
        document.addIP.submit();
    }else{
    alert("请输入正确的ip"); 
    return;
    }
    }else{
    alert("请输入正确的ip"); 
    return;
    }  

    </script>
    </head><body>
    <form name="addIP"  action="ViewaddServlet" method="post" id="addIP"> 
        <input type="hidden" name="opflag" value="add"/>   
      <input type="text" name="iptext" id="iptext" /> 
      <input type="button" name="sumbit" value="提交" onclick="checkIP()"/>  
    </form>  
    </body>
    </html>
      

  5.   

    我也是直接复制,但是没有跳到相应的ViewaddServlet里继续执行
      

  6.   

    <!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=gb2312" />
    <title>无标题文档</title>
    <script>
    function checkIP() 
    {  
    var strIP=document.getElementById('iptext').value 
    //对ip进行检验    
    strIP = strIP.replace(/\s/gi,"") 
    //用空值替换空格 
    if (strIP==""){ 
          alert("ip不能为空"); 
      return false; 

    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g        //匹配IP地址的正则表达式 
    if(re.test(strIP)) 

    if( RegExp.$1 <256 && RegExp.$2 <256 && RegExp.$3 <256 && RegExp.$4 <256){ 
      document.addIP.submit();
    }
    else{alert("请输入正确的ip"); 
    return false; }
    } else{
    alert("请输入正确的ip"); 
    return false;              
       }   

    </script>
    </head><body>
    <form name="addIP"  action="ViewaddServlet" method="post" id="addIP"> 
        <input type="hidden" name="opflag" value="add"/>   
      <input type="text" name="iptext" id="iptext" /> 
      <input type="button" name="sumbit" value="提交" onclick="return checkIP();"/>  
    </form>  
    </body>
    </html>