简体   繁体   English

从字符串中删除图像标记之外的html标记

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

I have a question regarding remove the html tags from string apart from the image tag. 我有一个关于从图像标签中删除字符串中的html标签的问题。 Let's say we have a string like : 假设我们有一个字符串:

<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>

In this we only need to remove the <p> and <span> like the html tags. 在这里我们只需要像html标签一样删除<p><span> But we need the image tag. 但我们需要图片标签。


Expected Result : 预期结果 :

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;">

Thanks in advance. 提前致谢。

$('span').contents().unwrap(); 。$( '跨')的内容()解开();

$('p').contents().unwrap(); $( 'P')的内容()解开()。;

For all elements except images: 对于除图像之外的所有元素

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

More here: 更多信息:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM