突出显示文本JSTL [英] Highlight text in JSTL
问题描述
我需要使用JSTL来显示文本。有两个阵列。
I need to display text using JSTL. There are two arrays.
数组a [一,二,三,九]
数组b [九,一,二]
array a [one, two, three, nine] array b [nine, one, two]
显示的文本应该大胆的,同时也是在B和元素留下,其余正常。
The displayed text should bold the elements in a that are also in b and leave the rest normal
有一个 两个三, 9
<c:forEach var="i" items="${a}">
<c:forEach var="j" items="${b}">
<c:choose>
<c:when test="${i==j}">
<strong><c:out value="${i}"/></strong>
</c:when>
<c:when test="${i!=j}">
<c:out value="${i}"/>
</c:when>
</c:choose>
</c:forEach>
</c:forEach>
我在想什么?在code显示器有一个突出,然后正常的3倍。
What am i missing? The code displays one highlighted and then normal 3 times
推荐答案
第二个 c为C:当&GT;
应该是 c为C :否则&GT;
您大概意思把&LT;强&GT;
和&LT; / STRONG&GT;
的围绕的之一 c为C:出&GT;
You probably meant to put the <strong>
and </strong>
around one of the <c:out>
.
另外,你的code将输出4 * 3 = 12个值。这是你故意的吗?结果
如果不是这样,也许改变 B
到列表
或设置
,并使用 b.contains(我)
会是你想要的。
Also, your code would output 4 * 3 = 12 values. Is that what you intended?
If not, perhaps changing b
to a List
or Set
, and using b.contains(i)
would be what you want.
更新
如果 B
是收藏
,preferably一个设置
,那么这将做到:
If b
is a Collection
, preferably a Set
, then this will do:
<c:forEach var="i" items="${a}">
<c:choose><c:when test="${b.contains(i)}">
<strong><c:out value="${i}"/></strong>
</c:when><c:otherwise>
<c:out value="${i}"/>
</c:otherwise></c:choose>
</c:forEach>
这篇关于突出显示文本JSTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!