簡體   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