XML .attributes不起作用

时间:2015-04-20 15:17:04

标签: javascript html ajax xml

在XML节点中,如下所示:

enter image description here

为什么这段代码不起作用?

                xml = $.parseXML( xml );
                console.log(xml);
                plot = $(xml).find("movie");
                aP = plot.attributes
                console.log(aP);

我的控制台日志未定义。 AP

我也试过aP = $(情节).attributes

1 个答案:

答案 0 :(得分:1)

attributes不是jquery属性。尝试plot.get(0).attributes这样就可以在元素上使用attributes属性,而不是在jquery对象上使用。

$(xml).find("movie"); //returns jquery object
$(plot) // is a jquery object of a jquery object. You really want your object to be a jquery object aye?
  

get(index):描述:检索与之匹配的元素之一   jQuery对象。

换句话说,你的get返回一个实际的元素。