我正在尝试使用纯 javascript 显示图像。我发现了各种使用 html 和 javascript 的示例,但没有纯 javascript 解决方案。这是我现在的非工作代码,
<script type="text/javascript">
if(document.images)
(new Image()).src="http://www.example.com/image.png";
</script>
最佳答案
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.
关于javascript - 仅使用 javascript 显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8261311/