该页面将正确显示图像的url文本。但我不确定如何将消息分配给img的src以显示图像。
<DIV class="msgStyle1" id="message">Waiting for image</DIV>
<div class="imgStyle1" id="message">
<img src=whatneedtogohere /></div>
function displayText(text) {
console.log(text);
document.getElementById("message").innerHTML=text;
window.castReceiverManager.setApplicationState(text);
};发布于 2014-03-22 04:29:12
固定HTML (切换类和ID,使ID唯一),为简单起见,增加了图片ID:
<div id="msgStyle1" class="message">Waiting for image</div>
<div id="imgStyle1" class="message">
<img src="" id="image" />
</div>JS:
document.getElementById('image').src = 'http://yourImagePathHere';在这里查看它的工作原理:http://jsfiddle.net/N3rCm/
发布于 2014-03-22 04:22:39
首先,你不应该在页面上有多个Id,这会弄乱你的JS。
接下来,如果可以的话,我会给你的图像一个类
//jquery example of what you would do
var imgSrc = 'http://wherever/youre/getting/this/from';
$('.myimageclass').attr('src', imgSrc);
//non jquery
var myImg = document.getElementsByClassName('myimageclass')[0]; //assuming it's the first one
//or if you can uniquely identify it
var myImg = document.getElementById('imgId');
myImg.src = imgSrc;https://stackoverflow.com/questions/22568665
复制相似问题