首页 > 编程语言 > 详细

验证码的全部代码(注意两种JavaScript的写法)

时间:2018-04-16 15:49:08      阅读:169      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="js/jquery-1.5.2.js"></script>
<script type="text/javascript">
$(function () {
$("#yanzenma").click(function () {
var img = document.getElementById("yanzenma");
img.src = "yanzenma.ashx?" + new Date();
});
});
</script>
</head>
<body>
<img src="yanzenma.ashx" id="yanzenma" />
</body>
</html>

 

 

 

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="js/jquery-1.5.2.js"></script>
<script type="text/javascript">
var GenXin = function () {
var img = document.getElementById("yanzenma");
img.src = "yanzenma.ashx?" + new Date();
};
</script>
</head>
<body>
<img src="yanzenma.ashx" id="yanzenma" onclick="GenXin()"/>
</body>
</html>

 

 

 

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace lianxi03
{
/// <summary>
/// yanzenma 的摘要说明
/// </summary>
public class yanzenma : IHttpHandler,IRequiresSessionState
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
Random r = new Random();
int a = r.Next(1000,10000);
context.Session["yanzenma"] = a;
using (Bitmap bmp = new Bitmap(50, 25))
{
using (Graphics g = Graphics.FromImage(bmp))
using (Font font = new Font(FontFamily.GenericSerif, 15))
{
g.DrawString(a.ToString(), font, Brushes.Red, new PointF(0, 0));
}
bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

验证码的全部代码(注意两种JavaScript的写法)

原文:https://www.cnblogs.com/lijian0755/p/8856031.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!