2014-09-30 51 views
0

您好我有一個Java腳本中有一些文本的功能,但現在我想添加一個圖片。如何在javascript中添加圖片的功能

如何在函數內插入圖像?

這裏是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

[插入圖像對象到HTML(http://stackoverflow.com/questions/12287856/insert-image-object-into-html) – Cherniv 2014-09-30 05:03:08

回答

-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">'; 
+0

是但在功能中的可能重複它 – Rokhsar 2014-09-30 04:56:11

+1

@Rokhsar什麼? – monkeyinsight 2014-09-30 04:57:52

+0

是的,它運行萬謝謝 – Rokhsar 2014-09-30 04:59:34

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; 

看到它:http://jsfiddle.net/yuanzm/x0zs7gb1/