2011-05-16 102 views
1

如何刪除標籤,但其中的內容仍然存在?使用jQuery從textarea中刪除標籤

事情是這樣的:

<textarea id="temp"> 
    ff<a href="sds.jpg" rel="tt[images]" title=""> cissttppp </a> 
</textarea> 

要成爲:

<textarea id="temp">ff cissttppp </textarea> 

感謝

回答

6
$('#temp').val(function(i,val) { 
    return $('<div>').html(val).text(); 
}); 
一個id

生活實例:http://jsfiddle.net/Pzny9/

+0

短期和甜蜜 - 仍然偉大工程,兩年多後 – 2013-08-31 10:26:13

0

增加了對

<textarea id="temp">ff<a href="sds.jpg" rel="tt[images]" title="" id="someA"> cissttppp </a></textarea> 


var temporary= $("#someA").text(); 
$("#someA").remove(); 
$("#temp").text($("#temp").text()+temporary); 
2

如何使用您的代碼一個很好的小注射?

http://jsfiddle.net/4dTEQ/

<textarea id="temp"><img onerror="alert((function(a){ return 'injection!'; })())" src=" sffsdfds" />ff<a href="sds.jpg" rel="tt[images]" title=""> cissttppp </a></textarea> 
+0

這會更佔有爲在OP評論。 – 2016-07-26 16:00:49