为什么设置innerHTML不起作用
Why is setting the innerHTML not working?
我的xml文档是这样的:
<Order>
<size width="16.5" height="19.5">
<width>16.5</width>
<height>19.5</height>
</size>
<type>photo</type>
</overlay>
<Mats></Mats>
<Openings></Openings>
<Moulding></Moulding>
<Glass></Glass>
</Order>
我正在尝试填写Mats标签的值。这是我的javascript代码:
function common_get_order_xml()
{
var parser = new DOMParser(); //create a new DOMParser
var doc = parser.parseFromString(common_get_common_order_xml(), "application/xml"); //convert the string to xml
console.log(doc); //outputs what is above
//doc.getElementsByTagName('Mats').innerHTML = mattes_get_mattes_xml().replace("<Mats>", "").replace("</Mats>", ""); //add the mattes
doc.getElementsByTagName('Mats').innerHTML = "TEST";
doc.getElementsByTagName('Openings').innerHTML = mattes_get_openings_xml(); //Add the openings
doc.getElementsByTagName('Moulding').innerHTML = moulding_get_moulding_xml(); //Add the moulding
doc.getElementsByTagName('Glass').innerHTML = glazing_get_glass_xml(); //Add the moulding
var serializer = new XMLSerializer(); //create a new XMLSerializer
common_order_xml = serializer.serializeToString(doc); //convert the xml back to a string
return doc;
}
但是当我输出文档时,Mats innerHTML不会被设置为"TEST">
当使用JavaScript和XML时,您不应该读取和设置innerHTML,Chrome和Firefox试图允许您这样做,但您可能会得到一些奇怪的行为。
尝试使用somthing.firstChild.data
而不是访问something.innerHTML
。
相关文章:
- 未捕获的类型错误:无法设置属性'innerHTML'如果为null,则将脚本移动到正文不会;不起作用
- InnerHtml 不起作用的 Javascript 变量
- innerHTML.value不起作用
- 使用replace方法替换innerHTML以及在Javascript中不起作用的正则表达式
- getElementById.innerHTML don'似乎不起作用
- innerHTML文本框在键入文本后不起作用
- innerHTML在IE 10中不起作用
- InnerHTML在IE中不起作用
- in innerHTML 中不起作用
- Javascript getElementByID().innerHTML() 不起作用
- innerHtml 在 ie for table 中不起作用
- getElementById innerHTML 对我不起作用
- IE9 问题:动态创建(通过 innerHTML)选项按钮和复选框不起作用
- 我想使用 innerHTML 显示变量的值,但我的代码不起作用
- .innerHTML 不起作用
- 试图将 document.write 替换为 innerHTML,但它不起作用
- innerHTML 在 if/else 中不起作用
- innerHTML 在事件处理程序函数 (Javascript) 中不起作用
- getElementById/InnerHTML 函数不起作用
- 带有getElementByClassName的innerHTML没有'不起作用