当我使用Javascript innerHTML调用它时,为什么我的图像不显示? [英] Why does my image not show up when I use Javascript innerHTML to call it?

查看:236
本文介绍了当我使用Javascript innerHTML调用它时,为什么我的图像不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Javascript的新手,我正在尝试一些事情。我正在使用函数使用innerHTML在表中加载图像。但是图像没有显示,除非我在函数底部调用alert(whatever),然后在警报可见时显示。
我使用的代码类似于(该函数从外部js文件调用)

I am pretty new to Javascript, and I was trying somethings out. I am using a function to load an image inside a table using innerHTML. But the image does not show up, unless I call alert("whatever") at the bottom of the function, then it shows up while the alert is visible. The code I am using is something like (the function is called from an external js file)

<script>
   function show(){
        document.getElementById('imageHolder1').innerHTML="<a href="#"><img='photos/picture.jpg' border=0/></a>";
    }
</script>

<body> <input name="b1" type="button" value="pics" onclick="show()"/>
<table><td id='imageHolder1'>picture</td></table>
</body> ``

我不明白为什么它不起作用,我看过的所有例子都是是相似的,我看到没有大的差异。即使我尝试没有标签它不起作用。欢迎任何帮助!在此先感谢,如果你对如何做到这一点有任何建议(因为我还在学习javascript,没有jquery)我也很感激。再次感谢!

I don't understand why it doesn't work, all the examples i have looked at are similar, I see no big differences.Even if I try with out the tag it doesn't work. Well any help welcome! Thanks in advance, and if you have any suggestions on how to do this (no jquery since I am still learning javascript) I would also appreciate it. Thanks again!

推荐答案

您的字符串中有错误:

document.getElementById('imageHolder1').innerHTML="<a href="#"><img='photos/picture.jpg' border=0/></a>";

应阅读

document.getElementById('imageHolder1').innerHTML="<a href='#'><img src='photos/picture.jpg' border=0/></a>";

(注意更换)

这篇关于当我使用Javascript innerHTML调用它时,为什么我的图像不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆