[英]Remove tags on Table HTML
我猜你在編碼輸出之前正在做str_replace(' ', '', $string)
。 所以你需要替換解碼的
:
str_replace(html_entity_decode(' '), '', $string);
或者
str_replace("\xc2\xa0", '', $string);
$("table:td").each(function(index) {
$(this).text($(this).text().replace(" ", ""));
});
選擇
$.each($("body").find("table"), function() {
this.innerHTML = this.innerHTML.split(" ").join("");
});
使用innerHTML
獲取原始 html 標記,然后替換所有
帶空字符串。
const td = document.querySelector('td'); document.querySelector('button').addEventListener('click', function() { const text = td.innerHTML; console.log('Before: ', text); td.textContent = text.replace(/ /gi, ''); console.log('After: ', td.innerHTML); });
<table> <tr> <td>Lorem Inpsum </td> </tr> </table> <button>Click Me!</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.