admin管理员组文章数量:1315362
Currently working on Loading image dynamic. If the custom image has the path it has to take the custom image not the default one if there is no custom image path are not available it has to load default image in the given ID.
As I am new to Javascript I am trying my below code.
var customImageurl = "custom_Image/web.png";
var defaultImageurl = "";
function loadGraphics(){
document.getElementById("loadImage").src = defaultImageurl;
}
loadGraphics();
<div id="loadImage"></div>
It was not working kindly help me.
Thanks in advance.
Regards Mahadevan
Currently working on Loading image dynamic. If the custom image has the path it has to take the custom image not the default one if there is no custom image path are not available it has to load default image in the given ID.
As I am new to Javascript I am trying my below code.
var customImageurl = "custom_Image/web.png";
var defaultImageurl = "";
function loadGraphics(){
document.getElementById("loadImage").src = defaultImageurl;
}
loadGraphics();
<div id="loadImage"></div>
It was not working kindly help me.
Thanks in advance.
Regards Mahadevan
Share Improve this question asked Dec 19, 2014 at 0:41 Mahadevan SivasubramanianMahadevan Sivasubramanian 871 gold badge3 silver badges12 bronze badges 4- show your html pls i want to check the img tag – AngularLover Commented Dec 19, 2014 at 0:46
-
You need to program your logic using
if
s like in your description. – PM 77-1 Commented Dec 19, 2014 at 0:46 - hi thanks @PM 77-1 can you please help me – Mahadevan Sivasubramanian Commented Dec 19, 2014 at 0:49
- What exactly do you need help with? – PM 77-1 Commented Dec 19, 2014 at 0:51
2 Answers
Reset to default 3Your problem is that a div has no src
attribute, as in your example you have <div id="loadImage"></div>
Your defaultImageurl
is also empty.
The solution is to use an <img/>
element:
var customImageurl = "custom_Image/web.png";
var defaultImageurl = "";
function loadGraphics(){
//v-- will not work!
document.getElementById("loadImage").src = defaultImageurl;
//v-- will work given your example conditions
document.getElementById("loadImage").src = customImageurl;
}
window.onload = function(){
loadGraphics();
};
<div id="loadImage-wrap">
<img id="loadImage" />
</div>
You are trying to use a src
attribute on a <div>
element.
本文标签: Dynamic load image amp Custom Load image using javascriptStack Overflow
版权声明:本文标题:Dynamic load image & Custom Load image using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741975421a2408092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论