繁体   English   中英

重新加载页面后图像未加载

[英]Image not loading after reloading the page

我有一个简单的应用程序,JS代码如下所示:

function refresh(){
    window.location.reload();
    document.getElementById("a").src="http://30.media.tumblr.com/tumblr_l8nftqa6oF1qbadnxo1_500.png";
}

按钮的HTML代码为:

<button id="refresh" onclick="refresh()">Refresh</button>

src所在的HTML代码如下所示:

<img id="a" style="position:absolute;top:390px;left:15px;height:254px;width:330px">

其余具有输入类型text的代码都可以,但是图像从未正确加载,我尝试了几件事,但是我是JS新手,所以不知道如何正确执行此操作。

您想使用以下代码:

function refresh(){
  window.location.reload();
}

window.onload = function () {
  document.getElementById("a").src="http://30.media.tumblr.com/tumblr_l8nftqa6oF1qbadnxo1_500.png";
}

您可能根本不需要重新加载页面。 在按钮上单击,您可以按如下方式获得新图像。 简而言之,如果不需要,请摆脱“ window.location.reload()”

`function refresh(){
    document.getElementById("a").src="http://ecx.images-amazon.com/images/I/3131FYr6f6L._SL500_AA300_.jpg"; }`

(请注意,我更改了图像路径,因为对帖子中的内容进行了“拒绝访问”。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM