更改img src通过jQuery:image将不会刷新 [英] Changing img src through jQuery: image won't refresh
问题描述
$('#photo_profile ').attr('src',fullPath).one(load,function(evt){
console.log(load);
} b $ b if(this.complete)$(this).load();
});
但是似乎img不刷新,而每当我更改src。
fullPath
就像 file:/// storage / emulated / 0 / MyAppFolder / Media / Profile%20Photos / profile.jpg
这是一个有效的路径,好像我杀了应用程式, - 启动它,显示正确的图像。
我做错了什么?
感谢
听起来像缓存问题。尝试使用一些随机参数阻止它:
$('#photo_profile')。prop('src',fullPath + ?'+ Math.random())
还有 src
是一个属性,因此使用 prop
而不是 attr
是有意义的。
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.complete) $(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
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
.
这篇关于更改img src通过jQuery:image将不会刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!