How to refresh the src of

前端 未结 4 1810
小鲜肉
小鲜肉 2020-12-03 01:30

where test.php generates an image with a random number.

Itried :

$(\'#verifyimage\').click(f         


        
相关标签:
4条回答
  • 2020-12-03 01:46

    Add a timestamp or a random number:

    var timestamp = new Date().getTime();
    $(this).attr('src',$(this).attr('src') + '?' +timestamp );
    
    0 讨论(0)
  • 2020-12-03 01:50

    In test.php set the headers of Content-Type: to image/jpeg

    0 讨论(0)
  • 2020-12-03 01:51

    Taking KPrimes great answer and adding in trackers suggestion, this is what I came up with:

    jQuery(function($) {
        // we have both a image and a refresh image, used for captcha
        $('#refresh,#captcha_img').click(function() {
           src = $('#captcha_img').attr('src');
       // check for existing ? and remove if found
           queryPos = src.indexOf('?');
           if(queryPos != -1) {
              src = src.substring(0, queryPos);
           }    
           $('#captcha_img').attr('src', src + '?' + Math.random());
           return false;
        });
    });
    
    0 讨论(0)
  • 2020-12-03 01:59

    You can force a refresh by appending a random string at the end, thus changing the URL:

    $('#verifyimage').click(function() {
        $(this).attr('src', $(this).attr('src')+'?'+Math.random());
    });
    
    0 讨论(0)
提交回复
热议问题