<xml>
元素是IE7中的保留元素吗?我似乎不是appendChild
这个元素或者在这个元素中。
DOM正在显示 -
<xml XMLDocument="[object]"></xml>
我需要在IE7中的DOM中附加<xml>
元素才能触发POS系统中的特定功能。有没有办法逃避这个或为IE7做这个,我只能使用.text
或.innerText
,但这不适用于我的情况,因为该函数查找XML元素而不是字符串。
使用vanilla javascript:
var jObj = { "Smart Shoes":{
"Product":"Smart Shoes",
"Price":24.99,
"Quantity":"1x "
},
"Denim Jeans":{
"Product":"Denim Jeans",
"Price":30,
"Quantity":"1x "
}
};
var xml = document.createElement("xml");
xml.setAttribute("id", "POSCMD");
xml.setAttribute("LateProcessing", "true");
var commands = document.createElement("commands");
xml.appendChild(commands);
var injFM = document.createElement("injectfieldmacro");
injFM.setAttribute("type", "field");
injFM.setAttribute("name", "FIELD_CLEAR");
commands.appendChild(injFM);
var injData;
for (var item in jObj) {
injData = document.createElement("injectdata");
injData.setAttribute("type", "literal");
injData.setAttribute("data", JSON.parse(jObj[item].Product)); // JSON.parse() older IE json2.js
injFM = document.createElement("injectfieldmacro");
injFM.setAttribute("type", "field");
injFM.setAttribute("name", "FIELD_UPC");
commands.appendChild(injData);
commands.appendChild(injFM);
}
document.getElementsByTagName("body")[0].appendChild(xml);
&#13;
甚至是jQuery
var jObj = {"Smart Shoes":{"Product":"Smart Shoes","Price":24.99,"Quantity":"1x "},"Denim Jeans":{"Product":"Denim Jeans","Price":30,"Quantity":"1x "}}
var xmlString = '<xml id="POSCMD" LateProcessing="true"><commands><injectfieldmacro type="field" name="FIELD_CLEAR"/>';
for (var item in jObj) {
if (jObj.hasOwnProperty(item)) {
xmlString += '<injectdata type="literal" data="' + jObj[item].Price + '"/>'; // I don't know where you got UPC from
xmlString += '<injectfieldmacro type="field" name="FIELD_UPC"/>'
}
}
xmlString += '</commands></xml>';
&#13;