繁体   English   中英

为什么设置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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM