简体   繁体   English

FireFox 和 IE Jquery 不工作

[英]FireFox & IE Jquery not working

I have created PHP GD image for captcha, file called image.php each time it generates a dynamic captcha image.我为验证码创建了 PHP GD 图像,文件名为image.php每次生成动态验证码图像。


In signup.php I havesignup.php我有

<img alt="" src="image.php"> 
<input type="button" id="btn" value="cant read captcha">
<!--btn is to load another captcha-->

jscript.js脚本.js

$("#btn").click(function(){  
    $("img").attr('src','image.php');
});

Works in Chrome, Safari, and Opera but not in IE and Firefox.适用于 Chrome、Safari 和 Opera,但不适用于 IE 和 Firefox。

How can I fix this or are there any alternative solutions?我该如何解决这个问题或者是否有其他解决方案?

Is the code running after the dom loads?代码是否在 dom 加载后运行? If not, try:如果没有,请尝试:

$(function(){
  $("#btn").click(function(){ 
    $("img").attr('src','image.php');  
  });
});

Is there an error in your console?你的控制台有错误吗?

Try a adding random number at the end of the url, this might be cache issue eg尝试在 url 末尾添加随机数,这可能是缓存问题,例如

$("#btn").click(function(){  
    $(this).prev("img").attr('src','image.php?rnd='+Math.random());
});

Maybe try this approach of adding a query string to prevent the browser caching.也许尝试这种添加查询字符串的方法来防止浏览器缓存。

How to reload/refresh an element(image) in jQuery 如何重新加载/刷新 jQuery 中的元素(图像)

Try this code试试这个代码

$(function(){

  $("#btn").live("click",function(){ 

       $("img").attr('src','image.php');  

  });
});

$("image").attr("src","image.php?timestamp=" + new Date().getTime()); $("image").attr("src","image.php?timestamp=" + new Date().getTime());


I think it was an issue of caching我认为这是缓存的问题
firefox and ie does not pick image from source again and again firefox 并且 ie 不会一次又一次地从源中选择图像
but it loads from its cache但它从缓存中加载
by changing name of image it is now working for me in all browsers通过更改图像的名称,它现在可以在所有浏览器中为我工作
thanx every one谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM