我设法使用 -
wxml = window.open("my_template.xml", "my_xml" );
我设法使用 -
xDoc = wxml.document;
xNodes = xExDoc.getElementsByTagName("myNodeName");
xValue = xNodes[i].getElementsByTagName("value")[0];
xValue.firstChild.nodeValue = nodeNewVal;
但我无法在屏幕上看到新的 DOM 值。
如何强制“通过 DOM 刷新屏幕”?
注意: reload() 不会有帮助,因为它会加载原始页面,并且我想查看带有 DOM 更改的页面。
编辑 - 我使用的代码:
XML 文件 (my_template.xml):
<myXmlRoot>
<device>
<input><name>"name 1"</name><value>{replaceMe!}</value></input>
<input><name>"name 2"</name><value>{replaceMe!}</value></input>
</device>
<device>
<input><name>"name 1"</name><value>{replaceMe!}</value></input>
<input><name>"name 2"</name><value>{replaceMe!}</value></input>
</device>
<device>
<input><name>"name 1"</name><value>{replaceMe!}</value></input>
<input><name>"name 2"</name><value>{replaceMe!}</value></input>
</device>
</myXmlRoot>
HTML 文件:
<html>
<head>
<title>Open XML in External Window</title>
</head>
<body>
<button onClick="fShowXmlInExternalWin()">Show XML </button> (does not show the updated version on the screen)
<script type="text/javascript" >
var wxml;
var xDoc;
var xDevices, xInputs;
var xDevice, xInput;
function fSetXmlAInput(iDevice, iNode, nodeNewVal) {
xInput = xInputs[iNode];
xValue = xInput.getElementsByTagName("value")[0];
// change node value:
// console.log("nodeVal: " + xValue.firstChild.nodeValue);
xValue.firstChild.nodeValue = nodeNewVal;
// console.log("newVal: " + xValue.firstChild.nodeValue);
}
function fSetXmlDevice(iDevice) {
xDevice = xDevices[iDevice];
xInputs = xDevice.getElementsByTagName("input");
fSetXmlAInput(iDevice, 0, "22");
fSetXmlAInput(iDevice, 1, "33");
}
function fShowXmlInExternalWin() {
wxml = window.open("my_template.xml", "my_xml" );
xDoc = wxml.document;
xDevices = xDoc.getElementsByTagName("device");
fSetXmlDevice(1);
return false;
}
</script>
</body>
</html>