我想知道是否可以删除标签,但留下的机智内容删除标签?例如,是否可以删除SPAN标签但将SPAN的内容留在那里?JS - 不删除内容
<p>The weather is sure <span>sunny</span> today</p> //original
<p>The weather is sure sunny today</p> //turn it into this
我一直在使用使用replaceWith()的this方法试过了,但它变成HTML到
<p>
"The weather is sure "
"sunny"
" today"
</p>
编辑:测试你的答案后,我意识到,我的代码有过错。我不断收到三个分割文本节点的原因是由于插入了SPAN标签。我会创建另一个问题来解决我的问题。
$(”内容()。unwrap() [1]:http://stackoverflow.com/questions/2308366/remove-element-with-jquery-but-leave-text – 2012-03-24 01:56:28
如何使用innerHtml?它是否给出相同的结果? – 2012-03-24 02:00:29
可能的重复[如何使用jQuery解开文本?](http://stackoverflow.com/questions/2409117/how-to-unwrap-text-using-jquery) – Joseph 2012-03-24 02:00:31