【问题标题】:JS + HTML, get src using javascriptJS + HTML,使用javascript获取src
【发布时间】:2011-07-25 22:52:51
【问题描述】:

假设我正在使用代码显示图像:

<img src="image.png"/>

我想用javascript定义src,你会怎么做

<script>
function getImage ()
{
   return "image.png";
}
</script>
<img src="Javascript:getImage()"/>

更新:

我需要它与 divx 播放器一起工作,通过 javascript 获取视频 url 参数

<object classid="clsid:*************" width="320" height="260" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab"> 
                <param name="custommode" value="none" /> 
                <param name="autoPlay" value="true" /> 
                <param name="src" value="Javascript:GetURL()" /> 
                <embed type="video/divx" src="Javascript:GetURL()" custommode="none" width="850" height="400" autoPlay="true"  pluginspage="http://go.divx.com/plugin/download/"> 
                </embed> 
            </object> 

有人对此有什么想法吗?

【问题讨论】:

标签: javascript image src


【解决方案1】:

你应该给你的标签单独的 ID,然后做

src = 'image.png';
document.getElementById('param1').setAttribute('value', src);
document.getElementById('embed1').setAttribute('src', src);

 <param id="param1" name="src" value="Javascript:GetURL()" /> 
                <embed id="embed1" type="video/divx" src="Javascript:GetURL()" custommode="none" width="850" height="400" autoPlay="true"  pluginspage="http://go.divx.com/plugin/download/">

【讨论】:

    【解决方案2】:

    您必须为图像分配一个 ID,然后使用它:

    document.getElementById('img_id').src="new_image.jpg";
    

    【讨论】:

      【解决方案3】:

      您可以使用 document.write() 使用视频 URL 动态写入嵌入代码,但您应该只在页面加载时执行此操作。

      【讨论】:

        猜你喜欢
        • 2013-04-03
        • 1970-01-01
        • 1970-01-01
        • 2014-08-22
        • 2016-04-09
        • 1970-01-01
        • 1970-01-01
        • 2018-01-14
        • 1970-01-01
        相关资源
        最近更新 更多