IE9中无效的字符DOM异常 [英] Invalid Character DOM Exception in IE9

查看:106
本文介绍了IE9中无效的字符DOM异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前在IE8中使用的JS的这一块现在在IE9中失败了。

The following piece of JS which used to work in IE8 is failing now in IE9.

document.createElement('<iframe id="yui-history-iframe" src="../../images/defaults/transparent-pixel.gif" style="position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;"></iframe>');

我得到以下异常:SCRIPT5022:DOM异常:INVALID_CHARACTER_ERR(5)

I get the following exception : SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)

以上代码是否符合标准。这个问题的解决方法是什么?

Is the above piece of code not according to standards. What's the fix for the issue?

推荐答案

createElement的API指定构造函数需要一个 / code>该物种的一个元素的名称。看来IE9更严格遵循标准。您可以完成与以下代码相同的操作:

The API for createElement specifies that the constructor wants a string that species the name of an element. It would appear that IE9 is more strictly following standards. You can accomplish the same thing you are trying to do with the following code:

var iframe = document.createElement("iframe");
iframe.setAttribute("id", "yui-history-iframe");
iframe.setAttribute("src", "../../images/defaults/transparent-pixel.gif");
iframe.setAttribute("style", "position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;");

http://msdn.microsoft.com/en-us/library/ms536389(v = vs85).aspx

这篇关于IE9中无效的字符DOM异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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