2010-12-02 60 views
1

首先我有一個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({ 
    …… 
    success: function (xml) { 
      alert($(xml).find("app[id='id-1']").find("html_code").text()); 
    } 

}); 
然而

,它只提醒「鏈接」,「ID - 1」,但我想<html_code>的所有內容包括<div>標籤,

所以我怎麼能實現使用jQuery?或我應該回到JavaScript使用「g etxml「......

謝謝:)

回答

1

你只需要使用.html()而不是.text()獲得的原始未過濾的善良,像這樣:

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

是的,謝謝你,我konw什麼是錯的與我在$ .ajax我寫的數據類型是「xml」,所以上面的情況,我曾經使用「HTML()」,它不能實現,你remaind我,所以我糾正它爲「」HTML 「,終於成功了! – hh54188 2010-12-02 12:16:14

相關問題