簡體   English   中英

從字符串中刪除圖像標記之外的html標記

[英]Remove html tags apart from the image tag from the string

我有一個關於從圖像標簽中刪除字符串中的html標簽的問題。 假設我們有一個字符串:

<p>MA2: Allow time for editing and other types of question revisions.<span class="AM"> <img src="img" title="{(1 if x>=0),(0 if x<0):}"style="vertical-align: middle;"> </span> <span class="AM"> </span> </p>

在這里我們只需要像html標簽一樣刪除<p><span> 但我們需要圖片標簽。


預期結果 :

MA2: Allow time for editing and other types of question revisions.<img src="img" title="{(1 if x>=0),(0 if x<0):}" style="vertical-align: middle;">

提前致謝。

。$( '跨')的內容()解開();

$( 'P')的內容()解開()。;

對於除圖像之外的所有元素

$('*').not('img').contents().unwrap();

更多信息:

http://api.jquery.com/contents/

http://api.jquery.com/unwrap/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM