createElement()在ie10中不起作用 [英] createElement() not working in ie10
本文介绍了createElement()在ie10中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的javascript文件中,我使用以下代码
In my javascript file i use the following code
var objResponseXmlDoc = document.createElement("XML");
var xmlmdInfo = objResponseXmlDoc.createElement("md");
var xmlviInfo = objResponseXmlDoc.createElement("vi");
var xmlcInfo = objResponseXmlDoc.createElement("c");
var xmlidInfo = objResponseXmlDoc.createElement("id");
当执行者到达xmlmdInfo时它会引发错误,因为对象不支持属性或方法'createElement'
但是IE 9工作正常
可以为我提供解决方案。
when executer reaches the xmlmdInfo it raise the error as "Object doesn't support property or method 'createElement'"
but upto IE 9 its working fine
can any one give me solution for this.
推荐答案
你应该用替换
objResponseXmlDoc.createElement
document.createElement
如果要追加创建的元素到objResponseXmlDoc
,然后使用objResponseXmlDoc.appendChild()
You should replaceobjResponseXmlDoc.createElement
withdocument.createElement
If you want to append the created elements toobjResponseXmlDoc
, then useobjResponseXmlDoc.appendChild()
var objResponseXmlDoc = document.createElement("XML");
var xmlmdInfo = document.createElement("md");
var xmlviInfo = document.createElement("vi");
var xmlcInfo = document.createElement("c");
var xmlidInfo = document.createElement("id");
objResponseXmlDoc.appendChild(xmlmdInfo); // after creating these elements, append them to objResponseXmlDoc
objResponseXmlDoc.appendChild(xmlviInfo);
objResponseXmlDoc.appendChild(xmlcInfo);
objResponseXmlDoc.appendChild(xmlidInfo);
考虑使用jQuery等方便的替代方案。这就是你可以用于所有这些DOM操作的方法:
http:/ /api.jquery.com/category/manipulation/dom-insertion-around [ ^ ],
http://api.jquery.com/category/manipulation/dom-insertion-inside [ ^ ],
http://api.jquery.com/category/manipulation/dom-insertion-outside [ ^ ],
http://api.jquery.com/category/manipu lation / dom-removal [ ^ ],
http://api.jquery.com/category/manipulation/ dom-replacement [ ^ ] 。
另请参阅: http://api.jquery.com / category / manipulation [ ^ ]。
如果您需要学习jQuery(强烈推荐),请参阅:
http://en.wikipedia.org/wiki/JQuery [ ^ ],
http://jquery.com [ ^ ],
http://learn.jquery.com [ ^ ],
http://learn.jquery.com/using-jquery-core [ ^ ],
http://learn.jquery.com/about-jquery/how-jquery-works [ ^ ](从这里开始)。
请记住,jQuery在设计时考虑了兼容性。
-SA
Consider using such a convenient alternative as jQuery. This is what you can use for all such DOM manipulations:
http://api.jquery.com/category/manipulation/dom-insertion-around[^],
http://api.jquery.com/category/manipulation/dom-insertion-inside[^],
http://api.jquery.com/category/manipulation/dom-insertion-outside[^],
http://api.jquery.com/category/manipulation/dom-removal[^],
http://api.jquery.com/category/manipulation/dom-replacement[^].
See also: http://api.jquery.com/category/manipulation[^].
If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com[^],
http://learn.jquery.com[^],
http://learn.jquery.com/using-jquery-core[^],
http://learn.jquery.com/about-jquery/how-jquery-works[^] (start from here).
Remember that jQuery is designed with compatibility in mind.
—SA
这篇关于createElement()在ie10中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文