最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing img src through jQuery: image won't refresh - Stack Overflow

programmeradmin5浏览0评论

I'm trying to change src dynamically through jquery in a Phonegap Build application, like this

$('#photo_profile').attr('src', fullPath).one("load", function(evt) {
                console.log("load");
            }).each(function() {
              if(thisplete) $(this).load();
            });

But it seems that the img does not refresh while the "load" log is shown each time I change the src.

fullPath is something like file:///storage/emulated/0/MyAppFolder/Media/Profile%20Photos/profile.jpg

And it's a valid path, as if I kill the app, then re-launch it, the displays the correct image.

Am I doing something wrong? Thanks

I'm trying to change src dynamically through jquery in a Phonegap Build application, like this

$('#photo_profile').attr('src', fullPath).one("load", function(evt) {
                console.log("load");
            }).each(function() {
              if(this.plete) $(this).load();
            });

But it seems that the img does not refresh while the "load" log is shown each time I change the src.

fullPath is something like file:///storage/emulated/0/MyAppFolder/Media/Profile%20Photos/profile.jpg

And it's a valid path, as if I kill the app, then re-launch it, the displays the correct image.

Am I doing something wrong? Thanks

Share Improve this question asked Nov 7, 2014 at 13:13 ApheXApheX 6852 gold badges10 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Sounds like caching issue. Try to prevent it with some random parameter:

$('#photo_profile').prop('src', fullPath + '?' + Math.random())

Also src is a property, so it makes sense to use prop instead of attr.

发布评论

评论列表(0)

  1. 暂无评论