【问题标题】:Display Image Using URL from GetElementByID使用来自 GetElementByID 的 URL 显示图像
【发布时间】:2018-06-21 15:31:48
【问题描述】:

下面的代码正在发送我想显示的图像的 URL,其中 div ID 为“目标”,到目前为止,我只能显示实际的 URL 地址而不是实际的图像。

            <script type='text/javascript'>
                function updateTarget( img ){
                    'use strict';
                    document.getElementById('target').innerHTML = img;
                }
            </script>

目标 div

            <div id = 'target'> </div>

任何帮助都将不胜感激,因为我正在努力在网上找到任何有用的示例。

【问题讨论】:

  • 你只解析 HTMl 中的 URl,并没有真正生成图像&lt;img /&gt;

标签: javascript html image url target


【解决方案1】:

使用这一行:

document.getElementById('target').innerHtml = '<img src="' +img+'"/>';

【讨论】:

    猜你喜欢
    • 2012-02-12
    • 2014-06-04
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多