function toText()
{
var convertHTML =$('#mainContent').html();
var ele = $(convertHTML + " > span").each(function(){
$(this).replaceWith($(this).text());
});
console.log(ele);
}
我的目標是替換以下內容替換HTML使用jQuery
<div id="mainContent">
test
<br>
1234
<br>
<span class="underline">test</span>
<br>
<span class="underline">1234</span>
</div>
而且希望我的功能,輸出測試<br> 1234 <br> test <br> 1234
這就是爲什麼我不能只使用文本(),因爲它需要還有<br>
!
完美答案+1 – LmC