我在用ASP做一个注册程序的时候,不知道咋的,点击“提交”按钮后没有响应javascript,而直接跳去check页面,也就是变成了服务器端来检测了,而我想它在客户端先检测好,问题出在哪里呢,帮忙看看。(注:千万不要说是什么IE的安全设置那里再设置一下,因为我已经试过了,已经点了恢复默认了还是一样不行)那个注册程序代码就多了点了,不放上来,我自己再写过一个简单的,测试了一下,还是没有响应JS,而我以前做的一个网站同样的做法,同样的代码却可以执行JS代码,我试着把这两个文件互换了位置,原先可以执行的还是可以执行,不可以执行还是不可以执行,郁闷啊,真捉弄人呢。自己改写的一个小的注册程序代码如下,看看:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>form</title>
<script type="text/JavaScript">
<!--
function checkform()
{
if(document.form1.username.value=="")
{
window.alert("请输入您的名字!");
document.form1.username.focus();
return false;
}
if(!/\w+@\w+(\.\w+)+/ig.test(form1.email.value))   
   {alert('邮件地址不对');
document.form1.email.focus();
return false;}
return true
}
//-->
</script>
</head><body>
<form id="form1" name="form1" method="post" action="">
  <table width="700" border="0" align="center" cellpadding="2" cellspacing="1">
    <tr>
      <td>用户:</td>
      <td><input name="username" type="text" id="username" /></td>
    </tr>
    <tr>
      <td>E-mail:</td>
      <td><input name="eMail" type="text" id="eMail" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="Submit" value="提交" onClick="return checkForm()" />
        <input type="reset" name="Submit2" value="重置" />
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>
我不知道我说的你们明不明白,如果不明白,我再说清楚一点,语言组织能力不好,呵呵,见谅!

解决方案 »

  1.   

    function checkForm()
    {
        if(document.form1.username.value=="")
            {
                window.alert("请输入您的名字!");
                document.form1.username.focus();
                return false;
                }
        if(!/\w+@\w+(\.\w+)+/ig.test(form1.eMail.value))   
              {alert('邮件地址不对');
                document.form1.eMail.focus();
            return false;}
        return true
    }
    注意大小写