【问题标题】:JSTL if-statement inside HTML-attributeHTML 属性中的 JSTL if 语句
【发布时间】:2010-12-09 01:13:46
【问题描述】:

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

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

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

【问题讨论】:

    标签: css jsp jstl jsp-tags


    【解决方案1】:
    
    <c:if test='true'> 
      <c:set value="someclass" var="cssClass"></c:set>
    </c:if> 
    <div class="${cssClass}">
       <p>some other stuff...</p>
    </div>
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        这对我有用!

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-12-23
          • 1970-01-01
          • 1970-01-01
          • 2015-02-16
          • 1970-01-01
          • 2013-06-01
          • 2012-03-15
          相关资源
          最近更新 更多