简体   繁体   English

为什么我的xml出现未定义的错误?

[英]Why am I getting an undefined error with my xml?

I was trying to follow the answer from here: Create XML in Javascript 我试图从这里得到答案: 用Javascript创建XML

I am getting an error in the console "undefined is not a function" for the 2nd line here: 我在第二行的控制台中收到“未定义不是函数”错误:

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() is a method of document , not of individual nodes. createAttribute()document的方法,而不是单个节点的方法。 You'll want something like: 您将需要类似:

imgsource = document.createAttribute('imgsrc');
imgsource.nodeValue = default_matte_source;
mat.setAttributeNode(imgsource);

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

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