window.onload=function(){
var fm=document.getElementById("reg");
fm.onsubmit=function(){
if (fm.yzm.value=="")
{
   alert("验证码不能为空!");
   return false;
}
else if(fm.yzm.value.length!=4)
{
   alert("验证码长度只能为4位数!");
   return false;
}
else if(fm.yzm.value!=<%=Session("CheckCode")%>)
   alert("验证码输写错误!");
   return false;}

</script>
</head><body>
<form id="reg" name="reg" method="post" action="aspinfo.asp">
  <table width="960" border="0" cellpadding="0">
    <tr>
      <td height="30"><div align="right">验 证 码:</div></td>
      <td height="30"><input name="yzm" type="text" class="yzm" maxlength="4"/>
          <img src="code.asp" name="safecode" width="48" height="18" align="absbottom" id="safecode"alert="验证码" /> [<a href="#" title="点击刷新验证码" class="STYLE1">刷新</a>]
        <label></label></td>
      <td><div id="erroyzm"></div></td>
    </tr>
    <tr>
      <td width="164" height="30">&nbsp;</td>
      <td width="349" height="30"><input type="submit" name="Submit" value="提交" /></td>
      <td width="439">&nbsp;</td>
    </tr>
  </table>
</form>

解决方案 »

  1.   

    发现这个Session("CheckCode")的值与 code.asp值不一样,,总是后一步  验证码:第二次显示:5462 Session("CheckCode")第一次是5462 就好像延迟了一样??
      

  2.   

    验证码的验证都是在服务器端进行验证的,你怎么在客户端做呢?
    code.asp的还没有执行,当然的得到的是上次的Session("CheckCode")啊你可以在页面的最后写
    var c = "<%=Session("CheckCode")%>"
    然后前面写
    else if(fm.yzm.value!=c)
      

  3.   

    那我用 <script src='hits.asp></script>静态文章点击 也可以统计,,而且数据也没错,按你意思,,那不就少统计了一次吗?