<script type="text/javascript"> window.onload = function () { var url = document.getElementById("url"); url.onclick = function () { var src = document.getElementById("imgCode").src; //函数用于使用当地时间返回当前Date对象中的毫秒值 document.getElementById("imgCode").src = src+"?d="+new Date().getMilliseconds(); }; } </script> 在body 里面做提交表单 <form method="post" action="Login.ashx"> 用户名: <input type="text" name="txtName" /><br /> 密码:<input type="password" name="txtPwd" /><br /> 验证码:<input type="text" name="txtCode" /> <a href="javascript:void(0)" id="url"><img src="ValidateCode.ashx" id="imgCode" /></a> </form>
//这里做验证
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
Common.ValidateCode validateCode = new Common.ValidateCode();
string code=validateCode.CreateValidateCode(4);
validateCode.CreateValidateGraphic(code, context);
}
+一个验证码的封装helper14.1108