[英]Remove tags on Table HTML
I made print layout with HTML.我用 HTML 制作了打印布局。 When I retrieve data from database, somehow the string results in the tags
当我从数据库中检索数据时,字符串以某种方式导致标签
as shown in the following picture:如下图所示:
And on console when a try to print_r()
, the result as shown in the following picture:在控制台上尝试print_r()
,结果如下图所示:
So, how the way to remove tag
那么,如何去除标签
on td
.在td
。 I've tried using trim()
and str_replace()
, but it doesn't work.我试过使用trim()
和str_replace()
,但它不起作用。
I guess you're doing str_replace(' ', '', $string)
before encoding output.我猜你在编码输出之前正在做str_replace(' ', '', $string)
。 So you need to replace decoded
所以你需要替换解码的
: :
str_replace(html_entity_decode(' '), '', $string);
Or或者
str_replace("\xc2\xa0", '', $string);
$("table:td").each(function(index) {
$(this).text($(this).text().replace(" ", ""));
});
Alternative选择
$.each($("body").find("table"), function() {
this.innerHTML = this.innerHTML.split(" ").join("");
});
use innerHTML
to get the raw html markup and then replace all
使用innerHTML
获取原始 html 标记,然后替换所有
with empty string.带空字符串。
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.