【发布时间】:2017-02-28 07:15:55
【问题描述】:
我想突出显示从服务器返回的文本,如下所示
This is my name <em>John</em>
我在服务器中调试,返回上面的字符串。 但是文本在浏览器中呈现时没有突出显示。
如下图所示
"This is my name <em>John</em>"
浏览器视图源码如下图
This is my name <em>John</em>
我应该转义“”符号吗? . 我在这个应用程序中使用 spring mvc 和 thymeleaf 来生成 html
<div th:if="${not #lists.isEmpty(results)}">
<h3>Search Results</h3>
<table class="table table-striped">
<tr>
<th>Id</th>
<th>Title</th>
</tr>
<tr th:each="result : ${results}">
<td th:text="${result.id}">Id</td>
<td th:text="${result.title}">Title</td>
</tr>
</table>
</div>
【问题讨论】:
-
您应该更改 HTML 页面上的编码,或者您应该使用 Java 中的 StringEscapeUtils 来转义您的文本。
-
这取决于您在浏览器中的显示方式。如果您使用的是 jquery,请尝试使用 $('id').html() 而不是 text()
标签: html spring-mvc highlight highlighting