簡體   English   中英

刪除表格 HTML 上的標簽

[英]Remove tags   on Table HTML

我用 HTML 制作了打印布局。 當我從數據庫中檢索數據時,字符串以某種方式導致標簽  如下圖所示:

在此處輸入圖片說明

在控制台上嘗試print_r() ,結果如下圖所示:

在此處輸入圖片說明

那么,如何去除標簽  td 我試過使用trim()str_replace() ,但它不起作用。

我猜你在編碼輸出之前正在做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 &nbsp;Inpsum &nbsp;&nbsp;&nbsp;</td> </tr> </table> <button>Click Me!</button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM