繁体   English   中英

从 html 转义特殊字符

[英]escape special characters from html

我正在创建一个 html 表。

<table class=" table table-striped table-bordered table-hover">
<thead>
<tr>
   <th>Remarks</th>
</tr></thead>
<tr>
   <td> hello <hi> html </td>
</table>

当我运行上面的代码时,我得到一个类似“hello html”的结果。 我需要显示全文,如" hello <hi> html "

使用html 实体

<td>hello &lt;hi&gt; html</td>

由于您标记了“Java”,我建议您使用Commons Text库将 html 字符转换为实体。

org.apache.commons.text.StringEscapeUtils#escapeHtml4

你可以像这样定义一个script

<script>
function loadPage() {
    document.body.querySelector("td").innerText = unescape(escape(document.body.querySelector("td").innerHTML));
}
</script>

并添加

onload="loadPage();" body

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM