【问题标题】:Jquery parsing xml - find a attribute of a tag inside other tagJquery解析xml - 在其他标签内查找标签的属性
【发布时间】:2011-12-02 13:07:15
【问题描述】:

仍在尝试解析 this xml:

我想用这段代码获取 param 标签的 z_depth 值

$(sif).find('layer[type="import"] param[name="z_depth"] real').each(function(){
zdepth_value = $(this).attr('value');
    });

并使用以下代码在 css 属性中打印:

$('<div style="position:relative; width:100%; height:100%; z-index:'+zdepth_value+'"></div>').appendTo('#object');

但是我没有得到属性值

我把代码放在: jsfidle

【问题讨论】:

    标签: jquery xml parsing


    【解决方案1】:

    我在 jsfiddle 中测试没有成功,可能测试 ajax 请求有一些限制。但是,这个脚本在我的机器上本地工作:

    <script type="text/javascript">
        var file_name = "http://henriquebarone.animatubo.com/spider/jquery/teste";
    
        $(document).ready(function () {
            $.ajax({
                type: "GET",
                url: file_name + ".xml",
                dataType: "xml",
                success: Parser
            });
        });
    
        function Parser(sif) {
            $(sif).find('layer[type="import"] param[name="z_depth"] real').each(function () {
                $('#object').append($('<span>' + $(this).attr('value') + '</span>'));
            });
        }
    </script>
    

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      • 2012-01-05
      • 1970-01-01
      • 2015-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多