使用 GetElementByID 中的 URL 显示图像

Display Image Using URL from GetElementByID

下面的代码发送了一张 URL 的图像,我想用 div ID 为 'target' 显示,到目前为止我只能显示实际的 URL 地址而不是实际图像。

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

目标div

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

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

使用这一行:

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