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