使用Jquery在IE和Firefox中无法动态更改图像src [英] Dynamically change image src using Jquery not working in IE and firefox
本文介绍了使用Jquery在IE和Firefox中无法动态更改图像src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为电子邮件实施验证码。点击 linkEmail
按钮电子邮件模式将打开。
我必须在点击 linkEmail
按钮点击时设置处理程序(CaptchaGenerator.ashx)生成的验证码图像。这是代码。
I am implementing a captcha for a email. when click on linkEmail
button email modal will open.
there i have to set captcha image generated by a handler (CaptchaGenerator.ashx) on click of linkEmail
button click. Here is the code for that.
$(".linkEmail").click(function () {
//Load captcha image
$('.imgCaptcha').attr('src', '/Custom/AppCode/Utilities/CaptchaGenerator.ashx');
$('#emailModal').modal();
});
以上代码在crome中工作正常但在IE和Firefox中无效 。
虽然我试过以下但没有运气。
Above code is working fine in crome but not working in IE and firefox. Although i have tried followings there is no luck.
HTML:
<p id="captchacontainerp" class="captchacontainer"></p>
-------------------------------------------------------------
$('#captchacontainerp').prepend($("<img id='imCaptcha' class='imgCaptcha' src='/Custom/AppCode/Utilities/CaptchaGenerator.ashx'></img>"));
-------------------------------------------------------------
var img = $('<img id="imCaptcha" class="imgCaptcha">');
img.attr('src', '/Custom/AppCode/Utilities/CaptchaGenerator.ashx');
$('#captchacontainerp').empty();
img.appendTo('#captchacontainerp');
---------------------------------------------------------------
$('#captchacontainerp').empty();
$('#captchacontainerp').append($("<img id='imCaptcha' class='imgCaptcha' src='/Custom/AppCode/Utilities/CaptchaGenerator.ashx'></img>"));
推荐答案
IE缓存所有GET请求,所以添加时间戳到您的请求网址例如:
IE caching all GET request, so add a timestamp to your request URL e.g :
$(".linkEmail").click(function () {
//Load captcha image
$('.imgCaptcha').attr('src', '/Custom/AppCode/Utilities/CaptchaGenerator.ashx?'+new Date().getTime());
$('#emailModal').modal();
});
这篇关于使用Jquery在IE和Firefox中无法动态更改图像src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文