HTML-attribute中的JSTL if语句

时间:2022-12-27 20:27:15

is it possible to do something like this in JSTL:

是否有可能在JSTL中做这样的事情:

<div class="firstclass<c:if test='true'> someclass</c:if>">
   <p>some other stuff...</p>
</div>

Is there any way to get this to work, or is there a better way to add a class by looking at a JSTL-if-statement?

有没有办法让它工作,或者是否有更好的方法通过查看JSTL-if语句来添加类?

3 个解决方案

#1


120  

It's also possible to use an EL expression directly like this:

也可以像这样直接使用EL表达式:

<div class="${booleanExpr ? 'cssClass' : 'otherCssClass'}">
</div>

#2


38  


<c:if test='true'> 
  <c:set value="someclass" var="cssClass"></c:set>
</c:if> 
<div class="${cssClass}">
   <p>some other stuff...</p>
</div>

#3


-3  

That works for me!

这对我行得通!

<div id="loginById" style="height:<% out.print(instanceClass.booleanMethod()? "250px": "150px");%>">

#1


120  

It's also possible to use an EL expression directly like this:

也可以像这样直接使用EL表达式:

<div class="${booleanExpr ? 'cssClass' : 'otherCssClass'}">
</div>

#2


38  


<c:if test='true'> 
  <c:set value="someclass" var="cssClass"></c:set>
</c:if> 
<div class="${cssClass}">
   <p>some other stuff...</p>
</div>

#3


-3  

That works for me!

这对我行得通!

<div id="loginById" style="height:<% out.print(instanceClass.booleanMethod()? "250px": "150px");%>">