HTML-attribute中的JSTL if语句
题
是否可以在JSTL中执行类似的操作:
<div class="firstclass<c:if test='true'> someclass</c:if>">
<p>some other stuff...</p>
</div>
有没有办法让它工作,或者是否有更好的方法通过查看JSTL-if语句来添加类?
解决方案
也可以直接使用EL表达式:
<div class="${booleanExpr ? 'cssClass' : 'otherCssClass'}">
</div>
其他提示
<c:if test='true'>
<c:set value="someclass" var="cssClass"></c:set>
</c:if>
<div class="${cssClass}">
<p>some other stuff...</p>
</div>
这对我有用!
<div id="loginById" style="height:<% out.print(instanceClass.booleanMethod()? "250px": "150px");%>">
不隶属于 StackOverflow