我有一个要求,如果status为0,那么添加一个css类active,否则添加一个css类active1,为此我做了类似关注
<c:forEach items="${parentList}" var="test">
<c:choose>
<c:when test="${test[1] eq 0}">
<li><a href="#" class="active" value="${test[0].id}-${test[0].category}" id="${parent.id}" onclick="return getQuestions(this);" >
${test[0].name }</a></li>
</c:when>
<c:otherwise>
<li><a href="#" class="active1" value="${test[0].id}-${test[0].category}" id="${parent.id}" onclick="return getQuestions(this);" >
<img src="${pageContext.request.contextPath}/resources/ui_resources/img/checked.jpg" alt="" height="20" width="20"/>${test[0].name }</a></li>
</c:otherwise>
</c:choose>
</c:forEach>
现在我的要求
${test[0].category}
是客户端,然后添加按钮<button name="delete/>
所以现在出现了4个条件
因此,如果使用jstl
循环,请告诉我如何使用if循环答案 0 :(得分:1)
而不是多个<c:choose />
使用<c:if />
和<c:var />
来确定要使用的类。您还可以使用<:if />
作为按钮,这将要求您将图像的渲染移动到css。
JSP看起来像这样(从头到尾)。
<c:forEach items="${parentList}" var="test">
<c:set var="clazz" value="active" />
<c:if test="${test[1] ne 0 and test[0].category ne 'client'}">
<c:set var="clazz" value="active1" />
</c:if>
<li>
<a href="#" class="${clazz}" value="${test[0].id}-${test[0].category}" id="${parent.id}" onclick="return getQuestions(this);" > ${test[0].name }</a>
<c:if test="${test[0].category eq 'client'}"><button name="delete" /></c:if>
</li>
</c:forEach>
您的CSS课程active1
a.active1 {
background-image: url('/resources/ui_resources/img/checked.jpg');
background-repeat: no-repeat;
padding-left: 25px; /* width of the image plus a little extra padding */
display: block;
}
答案 1 :(得分:0)
根据您的代码块,如何在c:if
阻止后添加<c:choose>
代码?
<c:forEach ...>
<c:choose ...>
</c:choose>
<%-- here to check buuton add or not --%>
<c:if test="${test[0].category == 'client'}"><button name="delete" /></c:if>
</c:forEach