2011-03-07 57 views
0

編輯:我特別使用Firefox 3.1+,因爲這是一個Intranet應用程序。jquery .text()返回html標籤,我該如何解決這個問題?

我有以下的html:

<em id="work-resize">re-size: from <span id="work-resize-from">3</span> to <span id="work-resize-to">5</span></em> 

使用jQuery我想要得到以下字符串:

're-size: from 3 to 5' 

我認爲使用.text()會做到這些,但是:

$('#work-resize').text(); 

退貨:

're-size: from <span id="work-resize-from">3</span> to <span id="work-resize-to">5</span>' 

我四處發現,我找不到原因。我可以使用remove tags which javascript returns with the text建議的功能,但我真的認爲.text()的要點是去掉標籤,所以使用我自己的功能似乎是多餘的。有沒有人有更好的解決方案,或建議如果我做錯了什麼?

回答

3

你確定嗎?我只是檢查它,您所描述的返回值聽起來很像.html()

$('<em id="work-resize">re-size: from <span id="work-resize-from">3</span> to <span id="work-resize-to">5</span></em>').text() 
"re-size: from 3 to 5" 

$('<em id="work-resize">re-size: from <span id="work-resize-from">3</span> to <span id="work-resize-to">5</span></em>').html() 
"re-size: from <span id="work-resize-from">3</span> to <span id="work-resize-to">5</span>" 
+0

呃。我發現錯誤,我選擇了錯誤的東西。現在刪除問題。儘管如此,感謝超級快速的迴應。 – LittleTreeX 2011-03-07 15:17:34

相關問題