如何使用jquery在xml中获取带有标签的内容

时间:2010-12-02 12:07:05

标签: xml jquery

首先我有一个xml:

<app id="id-1">
    <html_code>
           <div id="id-1" class="portlet">
                  <div class="portlet-header">Links</div>
                  <div class="portlet-content">id-1</div>
           </div>
    </html_code>
</app>

我想使用jquery $ .ajax来获取标签中的内容 我用

 $.ajax({
   ……
   success: function (xml) {
          alert($(xml).find("app[id='id-1']").find("html_code").text());
   }

}); 

但是,它只提醒“链接”,“id-1”,但我希望<html_code>的所有内容都包含<div>标记,

那么如何实现使用jquery?或者我应该回到javascript使用“getxml”......

谢谢你:)

1 个答案:

答案 0 :(得分:2)

您只需使用.html()代替.text()即可获得原始未经过滤的善良,如下所示:

alert($(xml).find("app[id='id-1']").find("html_code").html());