Heim > Fragen und Antworten > Hauptteil
if (storage.getItem('tootipXml')) {
var tootipObj = JSON.parse(storage.getItem('tootipXml'));
var xmlDom = createXml(tootipObj.opop);
console.log(xmlDom);
// console.log(typeof tootipObj.opop)
oXinHao.append(xmlDom)
}
function createXml(str){
if(document.all){
var xmlDom=new ActiveXObject("Microsoft.XMLDOM")
xmlDom.loadXML(str)
return xmlDom
}
else{
return new DOMParser().parseFromString(str, "text/xml")
}
}
这是代码,如果直接插入tootipObj.opop在dom里是这样的:
有两个引号,将tootipObj.opop转成dom对象后,插入又报错
请问该如何做?
阿神2017-04-11 11:36:19
var tootipObj = JSON.parse(storage.getItem('tootipXml'));
var parser = new DOMParser();
var newNode = parser.parseFromString(tootipObj.opop, "text/xml");
var xmlDom = createXml(tootipObj.opop);
oXinHao.append(newNode.documentElement)
可以改成这样