你好我在java脚本中有一个函数,它有一些文本,但现在我也想添加一个图像。
如何在函数内插入图像?
这是JAVASCRIPT代码:
<script type="text/javascript">
function CONshowElements(){
var Construction = "The construction company with several years of experience in projects valued over millions of USD having Service and Quality with satisfaction and appreciation of the clients";
document.getElementById("contents").innerHTML = Construction;
var image = new Image;
image.src = "images/SCALE Construction.png";
}
</script>
正文代码
<a href="construction.php"><div class="firstbox" id="Construction" onmouseover="CONshowElements(); return false; " >Construction</div></a>
答案 0 :(得分:0)
也许你想要这个答案:
function CONshowElements(){
var img = document.createElement("img");
img.setAttribute("src","images/SCALE Construction.png");
document.body.appendChild(img);
return false;
}
document.getElementById("Construction").onclick = CONshowElements;
答案 1 :(得分:-1)
您只想将图片移至var Construction
,以便
var Construction = 'The construction company with several years of experience in projects valued over millions of USD having Service and Quality with satisfaction and appreciation of the clients <img src="images/SCALE Construction.png">';