gpt4 book ai didi

javascript - XML .attributes 不起作用

转载 作者:行者123 更新时间:2023-11-28 01:32:49 25 4
gpt4 key购买 nike

在如下所示的 XML 节点中:

enter image description here

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

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

我的控制台日志未定义。一个P

我也试过 aP = $(plot).attributes

最佳答案

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): Description: Retrieve one of the elements matched by the jQuery object.

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

关于javascript - XML .attributes 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29751852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com