我想知道是否可以刪除標籤,但留下的機智內容刪除標籤?例如,是否可以刪除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