IE9 中的 Javascript 错误“SCRIPT5022:DOM 异常:INVALID_CHARACTER_ERR (5)”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8718602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Error in IE9 "SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)"
提问by Brian Webster
When I debug in IE9, It breaks on the following line
当我在 IE9 中调试时,它在以下行中断
{var c=document.createElement('<iframe id="'+a+'" name="'+a+'" />')
with the following error:
出现以下错误:
SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)
wmd.js, line 1 character 97
I am using OSQA software, and the bug may be reproduced with the latest version of IE9 (possibly with web developer toolbar installed)
我正在使用 OSQA 软件,该错误可能会在最新版本的 IE9 中重现(可能安装了 Web 开发人员工具栏)
http://meta.osqa.net/questions/ask/(bug may be reproduced as of 1/3/12)
http://meta.osqa.net/questions/ask/(错误可能在 1/3/12 重现)
If you visit that page, open up the javascript console, and attempt to upload any image using the image uploader, the error occurs.
如果您访问该页面,打开 javascript 控制台,并尝试使用图像上传器上传任何图像,则会发生错误。
This only breaks on IE9 for some reason
出于某种原因,这只会在 IE9 上中断
Update
更新
I'm a bit new to this javascript debugging business, but I opened up the watch menu and the value of "a" is: jUploadFrame1325624808664
我对这个 javascript 调试业务有点陌生,但我打开了 watch 菜单,“a”的值是: jUploadFrame1325624808664
回答by Wayne
The createElement
method expects onlythe name of the elementto create. Like this:
该createElement
方法预计仅该元素的名称创建。像这样:
var c = document.createElement("iframe")
Properties can be added to the new element later:
稍后可以将属性添加到新元素:
c.id = c.name = a;
Previous versionsof IE allowed you to provide this function with arbitrary HTML, but that was never part of the specand is no longer supported in IE9.
以前版本的 IE 允许您使用任意 HTML 提供此功能,但这从来不是规范的一部分,并且在 IE9 中不再受支持。
回答by Brian Webster
To use createElement
, you should only give it a tag name.
要使用createElement
,您应该只给它一个标签名称。
var c = document.createElement('iframe');
c.id = c.name = a;
回答by kennebec
var c=document.createElement('iframe');
c.id=a;