javascrip getElementById.src无响应问题
问题描述:GenerateValidateCode。aspx是用来生成验证码图片的,我想在网页中点击图片,获取新验证码(不刷新当前页)但是点击图片时,图片内容没有变。不知道为什么。
当前页面内容
<script type="text/javascript">
function Look()
{
window.alert('123123');
document.getElementById("Image1").src = "GenerateValidateCode.aspx";
}
<a onclick="Look()"><asp:Image ID="Image1" runat="server" Height="41px" Width="170px" /></a>
GenerateValidateCode.cs内容如下:
protected void Page_Load(object sender, EventArgs e)
{
//加载图片场景
string path = Server.MapPath("../images/bg.bmp");
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
//在图片场景中创建绘图对象Graphics
Graphics g = Graphics.FromImage(image);
//将随机字符串画在图片场景中
Font font =new Font("宋体",25);
SolidBrush brush = new SolidBrush(Color.Black);
PointF pf = new PointF(20f,4f);
g.DrawString(RandomNum(7), font, brush, pf);
image.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
Response.End();
}
------解决方案--------------------改一下 "GenerateValidateCode.aspx?" + Math.random();