我有以下 HTML 字符串,我只需要去除特定的跨度标签(具有 pre 属性的标签),但保留跨度内容
"<P>it <SPAN class='pre="it' ?>is is</SPAN> a movie</P>"
我需要以下输出,
"<P>it is is a movie</P>"
最佳答案
那么,首先您应该尝试使用有效的 HTML。然后你可以使用这段代码:
$("<p>it <span class='pre'>is is</span> a movie</p>")
.find('span') //Used 'span' here since you'll probably change the class name
.contents()
.unwrap()
.parent();
来自jQuery doc :
The .unwrap() method removes the element's parent. This is effectively the inverse of the .wrap() method. The matched elements (and their siblings, if any) replace their parents within the DOM structure.
您需要定位 span 的内容以展开 span 本身。
关于javascript - 从 HTML 内容 Jquery 中去除特定的 span 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22479651/