我试图从这里找到答案:Create XML in Javascript
我在控制台中的第二行收到错误“未定义不是函数”:
var mat = document.createElement("mat");
imgsource = mat.createAttribute("imgsrc");
imgsource.nodeValue = default_matte_source;
total_size = mat.createAttribute("total_size");
total_size.nodeValue = 7.5;
cpu = mat.createAttribute("cpu");
cpu.nodeValue = 12;
cid = mat.createAttribute("cid");
cid.nodeValue = default_matte_cid;
最佳答案
createAttribute()
是 document
的方法,而不是单个节点的方法。你会想要这样的东西:
imgsource = document.createAttribute('imgsrc');
imgsource.nodeValue = default_matte_source;
mat.setAttributeNode(imgsource);
关于javascript - 为什么我的 xml 出现未定义错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23892844/