Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的情况是这样的
<p><img src="/media/118711/banner.jpg" width="344" height="113" alt="Banner"></p>
我想使用 jquery 删除 p 标签,但我不需要删除内容(图像)。任何人都可以帮助我吗?
这个应该做...
$('p > *').unwrap();
js小提琴。
选择器$('p > *')仅在内容p是另一个标签时才起作用。如果它只包含文本,那么这个选择器不会命中它。这对我有用:
$('p > *')
p
$("p").each(function() { $(this).replaceWith($(this).html()); });