gpt4 book ai didi

javascript - 上传后图片src不变

转载 作者:行者123 更新时间:2023-11-28 02:59:12 25 4
gpt4 key购买 nike

我正在使用 Ajaxupload 插件进行上传,并且我在 ajaxupload 的 OnComplete 事件中使用此函数;

function degis(){
var a = "<?php echo $id; ?>";
document.getElementById("imga").src = "../artwork/"+a+"/logo.jpg?dummy=371662";
document.getElementById("imga").style.width = "500px";
document.getElementById("imga").style.height = "175px";
}

但是由于某种原因新上传的图像没有出现。我尝试了“?dummy=371662”,但没有成功。

我也将其用于 ajaxupload 的 Onsubmit 事件

function updeg(){
var a = "uploading.gif";
document.getElementById("imga").style.width = "50px";
document.getElementById("imga").style.height = "50px";
document.getElementById("imga").src = a;

}
</script>

这是该元素的 html

 <img id="imga" alt="" height="175px" src="../artwork/<?php echo $id; ?>/logo.jpg?dummy=371662" width="500px">

对此有什么建议吗?

最佳答案

根据您上面的编辑和评论,我认为您需要这样的东西:

function junk() {
return (new Date()).getTime() + Math.round(Math.random());
}

function degis() {
var img = document.getElementById("imga");
if (img) {
img.src = "../artwork/<?php echo $id; ?>/logo.jpg?nocache=" + junk();
img.style.width = "500px";
img.style.height = "175px";
}
}

您之前绕过缓存的尝试不起作用,因为您的“虚拟”值每次都是相同的。如上所述,通过使用 junk() 函数,您每次都会获得不同的随机值,确保图像无法被缓存。

关于javascript - 上传后图片src不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1626964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com