Changing the image source using jQuery

前端 未结 16 2072
天命终不由人
天命终不由人 2020-11-22 01:24

My DOM looks like this:

16条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 02:05

    I had the same problem when trying to call re captcha button. After some searching, now the below function works fine in almost all the famous browsers(chrome,Firefox,IE,Edge,...):

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

    'theUrl' is used to render new captcha image and can be ignored in your case. The most important point is generating new URL which forces FF and IE to rerender the image.

提交回复
热议问题