Firefox won't change image source

后端 未结 2 1191
说谎
说谎 2021-01-27 04:44

I\'m trying to change an image in JavaScript+Prototype by changing the \"src\" attribute of the element. It works fine in IE, but not in Firefox. I don\'t get any errors and the

2条回答
  •  梦如初夏
    2021-01-27 05:22

    This function works fine in all browsers(chrome,Firefox,IE,Edge,...):

    function recaptcha() {
      $("#captcha-img").attr('src', "");
      setTimeout(function(){
           $("#captcha-img").attr('src', "captcha?"+new Date().getTime());
      }, 0);
     }
    

    The important point is generating new URL which forces FF and IE to re-render the image.

提交回复
热议问题