我有一个关于从字符串中删除除图像标签之外的 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>
这里我们只需要删除 <p>
和<span>
就像 html 标签一样。 但是我们需要图像标签。
预期结果:
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;">
提前致谢。
最佳答案
$('span').contents().unwrap();
$('p').contents().unwrap();
对于除图像之外的所有元素:
$('*').not('img').contents().unwrap();
更多信息请参见:
关于javascript - 从字符串中删除除图像标签之外的 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23669959/