开发者

IE error with javascript that works fine on Firefox and Chrome

document.getElementById("displayImage").开发者_如何学编程getElementsByTagName("img")[0].src = "image2.png"

I seem to remember that for IE, you need to add a <meta> tag of some description, but I can't find which one.

If it helps:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0;

Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR

3.5.30729; .NET CLR 3.0.30729) Timestamp: Tue, 6 Sep 2011 12:23:00 UTC

Message: Object doesn't support this property or method


As I mentioned in a comment above, the code is fine; there's no need for a meta tag. I suspect there is some other JavaScript error occurring before the code executes. It's either that, or the elements don't exist in the document when the code executes.


try setting the src attribute for the image like this

var image = document.getElementById("displayImage").getElementsByTagName("img")[0];
image.setAttribute("src",path);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜