是的,只要您去掉检查e-mail的那一条IF语句就可以正确执行了,我在注释中有说明:为什么这一条是错误的?

解决方案 »

  1.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <script language="JavaScript">
    <!--
      function mm_findobj(n,d)
      {
        var p,i,x;
    if(!d)
      d=document;
    if((p=n.indexOf("?"))>0 && Parent.frames.Length)
    {
      d=parent.frames[n.substring(p+1)].document;
      n=n.substring(0,p);
    }
    if(!(x=d[n])&& d.all)
      x=d.all[n];
    for (i=0;!x && i<d.forms.length;i++)
      x=d.forms[i][n];
    for (i=0;!x && d.layers && i<d.layers.length;i++)
      x=mm_findobj(n,d.layers[i].document);
    return x;
     }
    /*前面这一个函数,我看得出来是检查对象的,但p=n.indexOf("?"))>0这个检测有什么用呢?还用Parent.frames.Length,为什么要加Parent这个东东呢?也就是这个代表什么意思呢?还有这里几个IF语句在判断什么东西呢?
    p=n.indexOf("?")>0 我确实看不出来啥意思,我怀疑是表单在当页提交的时候由于有参数会产生?号。parent.frames.length也不是恨清楚,只是怀疑这个页面是由父页面提交的一个文件而已,但是为什么要取得父页面的帧的个数就不清楚了。
    第一个if是根据d判断浏览器的类型来选择document还是document.all,判断如果是netscape
    第二个if是可能是判断父页面的帧的个数,也就是说这个判断函数并不是在这个子页面里面的,而是根据父页面来判断的
    第三个if是判断是否是ie,*/
     function checkall(str)
     {
       var d,i,formname,emailexp,broc_val;
       d=mm_findobj(str);/*请问这个函数只传一个参数,那么对于函数来说,第二个函数是否就是NULL了呢?还有直接d=mm_findobj(str),那么d是这个 函数最后一条语句:return x 的值呢?还是什么?谢谢
    第二个参数是null,return x是返回表单中的某个对象,对应的i这个元素
       */
       emailexp=/^[_\.a-z0-9]+@[a-z0-9]+[\.][a-z0-9]{2,3}$/gi;
       broc_val=0;
       for (i=1;i<d.length-1;i++)
       {
         if(d[i].value.replace(/ /g,'')=='')
     {
       alert('some information is missing.');
       return false;
     }
     if(d[i].name=='email_home' && emailexp.test(d[i].value.replace(/ /g,""))==false)
     /* 为何emailexp.test(d[i].value.replace(//g,''))==false这个是错误的?replace是何作用呢?其实它只是测试它是不是空的还有是不是符合正则表达式
     //g当然是错误的,因为你没有匹配表达式,第一个/后面根本没有字符怎么匹配阿?只有/g作为全局搜索,具体情况你可以看正则表达式的帮助文件,前面一个/根本不起作用。问题是你想做什么就需要什么表达式,但是你匹配的表达式只是作为全局搜索用""替换什么那?? */ {
       alert('invalid e-mail address');
       return false;
      }
      if(d[i].name=='brochure1' && d[i].checked==true)broc_val=1;
      if(d[i].name=='brochure2' && d[i].checked==true)broc_val=1;
    }
    if(broc_val==0)
    {
     alert('some information is missing');
     return false;
     }
    }
    function run_submit(str)
    {
     var d;
     d=mm_findobj(str);
     if(checkall('theform')!=false)
        d.submit();
    }
    //-->
    </script>
    </head>
    /*下面只是生成了一个表单,最主要的是前面检查表单的内容*/
    <body bgcolor="#000000" text="#33ff33" link="#33ff33" vlink="#44ff44" alink="#ff33ff">
    <table width="488" border="0" cellpadding="0" cellspacing="2" align="center">
      <form name="theform" method="post" action="" onSubmit="return checkall('theform')">
        <tr> 
          <td class="name">name:</td>
          <td> <input type="text" name="name" size="20" maxlength="20" class="formcss"> 
          </td>
          <td class="name">tel:</td>
          <td> <input type="text" name="tel" size="20" maxlength="20" class="formcss"> 
          </td>
        </tr>
        <tr> 
          <td class="name">title:</td>
          <td> <input type="text" name="title" size="20" maxlength="20" class="formcss"> 
          </td>
          <td class="name"><font color="#663300">fax:</font></td>
          <td> <input type="text" name="fax" size="20" maxlength="20" class="formcss"> 
          </td>
        </tr>
        <tr align="left"> 
          <td class="name">company:</td>
          <td> <input type="text" name="company" size="20" maxlength="20" class="formcss"> 
          </td>
          <td class="name" hiegth="28">e-mail:</td>
         <td height="28"> <input type="text" name="email" size="20" maxlength="30" class="formcss"> 
          </td>
        </tr>
        <tr align="left"> 
          <td height="28" class="name">address:</td>
          <td height="28"> <input type="text" name="address" size="20" class="formcss"> 
          </td>
          <td rowspan="3" height="28" valign="top" class="name">message:</td>
          <td rowspan="3" height="28" valign="bottom"> <textarea name="message" cols="18" rows="4" class="formcss"></textarea> 
          </td>
        </tr>
        <tr> 
          <td class="name">&nbsp;</td>
          <td> <input type="text" name="address2" size="20" class="formcss"> </td>
        </tr>
        <tr> 
          <td class="name">country:</td>
          <td> <input type="text" name="country" size="20" maxlength="30" class="formcss"> 
          </td>
        </tr>
        <tr align="center" valign="middle"> 
          <td colspan="4" height="35"> <input type="submit" name="submit" value="send" class="formcss"> 
          </td>
        </tr>
      </form>
    </table>
    </body>
    </html>