<?xml version="1.0" encoding="utf-8"?>
<PlateTrees>
<Plate ID="1" Name="股票">
<Plate ID="2" Name="A股"></Plate>
<Plate ID="3" Name="港股"></Plate>
<Plate ID="4" Name="美股"></Plate>
</Plate>
<Plate ID="5" Name="外汇">
<Plate ID="6" Name="欧/美"></Plate>
<Plate ID="7" Name="镑/美"></Plate>
<Plate ID="8" Name="澳/美"></Plate>
<Plate ID="9" Name="美/日"></Plate>
<Plate ID="10" Name="美/加"></Plate>
<Plate ID="11" Name="美/瑞"></Plate>
</Plate>
</PlateTrees>
现在给你一个plate的ID,找出他的子plate。并且遍历他的所有子plate。
比如:找出ID为5的plate的子plate。谢谢!

解决方案 »

  1.   

    $("#5").each(function(){
       alert($(this).attr("Name"));
    });
    我没测试过,不知道对不对。
      

  2.   

    $("PlateTrees>plate").each(function(){
      alert($(this).find("ID").text())
    })
      

  3.   


    $.get(
        "xxx.xml",
        function(xml){
            var text = $(xml).find("Plate#2").text();
            alert(text);
        }
    );
      

  4.   

    如果给你的不是ID是Name呢 所以你这个明显不对的 要求:找出ID为5的plate的子plate。
    我想肯定是有两步,先找出ID为的Plate,然后再找出它的子plate,然后再遍历。
      

  5.   

    先问一下 怎么找到ID为5的Plate
    用jquery怎么写,是不是需要遍历,然后依次判断每个节点来找到ID为5的节点?
      

  6.   

    alert($("PlateTrees Plate[id='5']").text());
      

  7.   


    ...
    $("Plate[ID=5]",xmlDoc).children("Plate");