javascript - 仅使用 javascript 显示图像

标签 javascript image

我正在尝试使用纯 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/

相关文章:

javascript - ColdFusion XML 到 Javascript 变量

python - 使用 python 模块 image 去除图像中的红色的函数

android - 使用 webview 下载图像

.net - Bitmap.Height和VerticalResolution之间的区别

javascript - knockout.mapping.js,是否可以只更新映射变量的一部分?

javascript - 在点击jquery时绑定(bind)两个事件

javascript - 使用javascript更改html标签并在服务器端获取值

javascript - 大背景图像导致滚动时滞后

c# - 拍摄低质量的屏幕照片

javascript - 更正可拖动元素的像素位置以从任意 Angular 开始