HTML 属性内的 JSTL if 语句

发布于 2024-08-08 02:45:48 字数 235 浏览 2 评论 0原文

是否可以在 JSTL 中执行类似的操作:

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

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

is it possible to do something like this in 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谁把谁当真 2024-08-15 02:45:48

也可以直接使用 EL 表达式,如下所示:

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

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

<div class="${booleanExpr ? 'cssClass' : 'otherCssClass'}">
</div>
[浮城] 2024-08-15 02:45:48

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

<c:if test='true'> 
  <c:set value="someclass" var="cssClass"></c:set>
</c:if> 
<div class="${cssClass}">
   <p>some other stuff...</p>
</div>
为你鎻心 2024-08-15 02:45:48

对我来说,以下内容与 Java 结合使用:

<%
String cssClass = 'oneClass';

if(i >= 5){
   cssClass += " anotherClass";
}

<div cssClass="<%= cssClass %>" >... </div>
%>


For me the following worked in combination with Java:

<%
String cssClass = 'oneClass';

if(i >= 5){
   cssClass += " anotherClass";
}

<div cssClass="<%= cssClass %>" >... </div>
%>


匿名。 2024-08-15 02:45:48

这对我有用!

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

That works for me!

<div id="loginById" style="height:<% out.print(instanceClass.booleanMethod()? "250px": "150px");%>">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文