使用javascript在div中显示图像? [英] Display an image in a div with javascript?
本文介绍了使用javascript在div中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的js不好,但我想我需要使用getElementbyId,有些人认为:
my js is not good, but I'm thinking I'm going to need to use the getElementbyId some think like:
if (a == ‘tick’)
document.getElementById(‘imageDiv’) = tick.gif
else
document.getElementById(‘imageDiv’) = cross.gif
<div id="imageDiv"></div>
但不起作用。
推荐答案
使用它,它应该工作。
<script type="text/javascript">
function image(thisImg) {
var img = document.createElement("IMG");
img.src = "images/"+thisImg;
document.getElementById('imageDiv').appendChild(img);
}
if (a == 'tick') {
image('tick.gif');
} else {
image('cross.gif');
}
</script>
<div id="imageDiv"></div>
这篇关于使用javascript在div中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文