<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>验证网址</title>
<style type="text/css">
<!--
.style1 {font-size: 13px}
.style2 {
font-size: 12px;
color: #FF0000;
}
.style3 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">
function checkURL(URL){
var str=URL;
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; 
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
   return true;
}else{
   return false;
}
}
</script>
<script language="javascript">
function checkform1(){
var www=form1.www.value;
if(www==""){
   alert("请输入个人主页地址!");
   document.form1.www.focus();     
}else{
   if(!checkURL(www)){
    alert("您输入的个人主页地址不合法!");
    document.form1.www.focus();
    return;
   }
}
form1.submit();
}
</script><body>
<table width="450" border="1" cellpadding="0" cellspacing="0" background="images/sss.JPG"><form name="form1" method="post" action="eecdss.php"> <tr align="center">
    <td height="24" colspan="2" class="style1">验证网址</td>
    </tr>
<tr>
    <td height="20" align="center" class="style1">个人空间:</td>
    <td class="style3"><input name="www" type="text" id="www" size="20" maxlength="70">
      <span class="style2"> * 请输入正确的个人空间地址</span></td>
</tr>
<tr>
    <td height="24" align="center"> </td>
    <td class="style3"><input type="button" name="Submit" value="提交" onClick="checkform1();">
      <span class="style2">      (*为必填项目)</span>        <input type="reset" name="Submit2" value="重置">
      
      </td>
</tr>
</form>
</table>
</body>
</html> 

解决方案 »

  1.   

    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    <title>验证网址 </title> 
    <style type="text/css"> 
    <!-- 
    .style1 {font-size: 13px} 
    .style2 { 
    font-size: 12px; 
    color: #FF0000; 

    .style3 {font-size: 12px} 
    --> 
    </style> 
    </head> 
    <script language="javascript"> 
    function checkURL(URL){ 
    var str=URL; 
    //下面的代码中应用了转义字符"\"输出一个字符"/" 
    var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; 
    var objExp=new RegExp(Expression); 
    if(objExp.test(str)==true){ 
      return true; 
    }else{ 
      return false; 


    </script> 
    <script language="javascript"> 
    function checkform1(){ 
    var www=form1.www.value; 
    if(www==""){ 
      alert("请输入个人主页地址!"); 
      document.form1.www.focus();  
      return false;  
    }else{ 
      if(!checkURL(www)){ 
        alert("您输入的个人主页地址不合法!"); 
        document.form1.www.focus(); 
        return false
      } 

    form1.submit(); 

    </script> <body> 
    <table width="450" border="1" cellpadding="0" cellspacing="0" background="images/sss.JPG"> <form name="form1" method="post" action="eecdss.php"> <tr align="center"> 
        <td height="24" colspan="2" class="style1">验证网址 </td> 
        </tr> 
    <tr> 
        <td height="20" align="center" class="style1">个人空间: </td> 
        <td class="style3"> <input name="www" type="text" id="www" size="20" maxlength="70"> 
          <span class="style2"> * 请输入正确的个人空间地址 </span> </td> 
    </tr> 
    <tr> 
        <td height="24" align="center"> </td> 
        <td class="style3"> <input type="button" name="Submit" value="提交" onClick="return checkform1();"> 
          <span class="style2">      (*为必填项目) </span>        <input type="reset" name="Submit2" value="重置"> 
          
          </td> 
    </tr> 
    </form> 
    </table> 
    </body> 
    </html> 
      

  2.   

    表单没验证通过应该返回FALSE,这样就不会提交了正确如下:
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    <title>验证网址 </title> 
    <style type="text/css"> 
    <!-- 
    .style1 {font-size: 13px} 
    .style2 { 
    font-size: 12px; 
    color: #FF0000; 

    .style3 {font-size: 12px} 
    --> 
    </style> 
    </head> 
    <script language="javascript"> 
    function checkURL(URL){ 
    var str=URL; 
    //下面的代码中应用了转义字符"\"输出一个字符"/" 
    var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; 
    var objExp=new RegExp(Expression); 
    if(objExp.test(str)==true){ 
      return true; 
    }else{ 
      return false; 


    </script> 
    <script language="javascript"> 
    function checkform1(){ 
    var www=form1.www.value; 
    if(www==""){ 
      alert("请输入个人主页地址!"); 
      document.form1.www.focus();    
      return false;
    }else{ 
      if(!checkURL(www)){ 
        alert("您输入的个人主页地址不合法!"); 
        document.form1.www.focus(); 
        return false;
      } 

    form1.submit(); 
    return true;

    </script> <body> 
    <table width="450" border="1" cellpadding="0" cellspacing="0" background="images/sss.JPG"> <form name="form1" method="post" action="eecdss.php"> <tr align="center"> 
        <td height="24" colspan="2" class="style1">验证网址 </td> 
        </tr> 
    <tr> 
        <td height="20" align="center" class="style1">个人空间: </td> 
        <td class="style3"> <input name="www" type="text" id="www" size="20" maxlength="70"> 
          <span class="style2"> * 请输入正确的个人空间地址 </span> </td> 
    </tr> 
    <tr> 
        <td height="24" align="center"> </td> 
        <td class="style3"> <input type="button" name="Submit" value="提交" onClick="return checkform1();"> 
          <span class="style2">      (*为必填项目) </span>        <input type="reset" name="Submit2" value="重置"> 
          
          </td> 
    </tr> 
    </form> 
    </table> 
    </body> 
    </html> 
      

  3.   

    alert("请输入个人主页地址!"); 
      document.form1.www.focus();   //加上这句
     return;
      

  4.   


    function checkform1(){
    var www=form1.www.value;
    if(www==""){
      alert("请输入个人主页地址!");
      document.form1.www.focus();   
    return false;
    }else{
      if(!checkURL(www)){
        alert("您输入的个人主页地址不合法!");
        document.form1.www.focus();
        return false;
      }
    }
    form1.submit();
    return true;
      

  5.   

    <input name="www" type="text" id="www" size="20" maxlength="70">name="www"  id="www" 里面的WWW我能换成其它的吗?要怎么换!
      

  6.   

    当然可以换了,比如换成url
    <input name="url" type="text" id="url" size="20" maxlength="70">另外别忘了,JS里面也要相应的修改
      

  7.   

    哎呀,把这问题弄复杂了,我说明白点吧,
     <input name="uucs" type="text" id="uucs" size="20" maxlength="70"> 
    这段表单是开始要提交到 action="eecdss.php"这里的,
    然后我要给这个表单加个网址验证,就从网上找了这段代码?  </style> 
      </head> 
      <script language="javascript"> 
    function checkURL(URL){ 
    var str=URL; 
    //下面的代码中应用了转义字符"\"输出一个字符"/" 
    var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; 
    var objExp=new RegExp(Expression); 
    if(objExp.test(str)==true){ 
      return true; 
    }else{ 
      return false; 


      </script> 
      <script language="javascript"> 
    function checkform1(){ 
    var www=form1.www.value; 
    if(www==""){ 
      alert("请输入个人主页地址!"); 
      document.form1.www.focus(); 
    return false; 
    }else{ 
      if(!checkURL(www)){ 
        alert("您输入的个人主页地址不合法!"); 
        document.form1.www.focus(); 
        returnfalse; 
      } 

    form1.submit(); 

      </script>
    <input name="www" type="text" id="www" size="20" maxlength="70"> 
    <input type="button" name="Submit" value="提交" onClick="returncheckform1();"> 
           <span class="style2">      (*为必填项目)  </span>         <input type="reset" name="Submit2" value="重置"> 然而开始表单里的name="uucs" id="uucs" 是不能动的,而我找的代码里的表单的是name="www"  id="www"
    我就想知道这个该怎么改,
    谢谢各位了!