2011-11-24 49 views
0

我正在嘗試使用純粹的JavaScript顯示圖像。我發現使用html和javascript工作的各種示例,但沒有純JavaScript解決方案。這裏是我現在的非工作代碼,僅使用javascript顯示圖像

<script type="text/javascript"> 
    if(document.images) 
     (new Image()).src="http://www.example.com/image.png"; 
</script> 

回答

3
var img = new Image(); 
img.src = "http://www.example.com/image.png"; 
document.body.appendChild(img); //Make sure you put the element in the DOM, otherwise it won't be visible.