【问题标题】:XML .attributes not workingXML .attributes 不起作用
【发布时间】:2015-06-27 09:54:13
【问题描述】:

在如下所示的 XML 节点中:

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

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

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

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

【问题讨论】:

    标签: javascript html ajax xml


    【解决方案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 返回一个实际的元素。

    【讨论】:

    • 谢谢兄弟,一口气回答了很多
    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多