快速版本:
如果我做一个div,并在其中放一张图片,它就很好了。
this
<img id="main_image"; src="~/images/tea_offer.jpg" style="width:100%; height:100%" />
gives
localhost/images/tea_offer.jpg
但是后来我尝试使用javascript更改图像
this
document.getElementById("main_image").src = "images/cake.jpg"
gives
localhost/home/~/images/cake.jpg
并且图像不起作用。我认为这====> localhost / home /〜/ images / cake.jpg。是错的。请帮助。
长版。
我有一个简单的网站,它有一个背景图片和一个蓝色框。单击蓝色框时,背景图像会更改。图像存储在本地的wwwroot中。单击蓝色框时,背景图像只是变成白色,而我的计算机无法找到它要寻找的图像。
proof the images are stored in propper place with propper name
如何获取javascript以查找类似于html的图像?
更多信息:https://coderwall.com/p/8nhqeg/relative-paths-from-the-root-in-javascript