You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为JSTL<c:if>标签内的文本设置CSS颜色?

解决方案

不需要更换<c:if>标签,直接在条件成立时显示的文本外层嵌套一个带内联CSS的<span>标签就能实现需求,不会影响labelOnLeft类下的其他内容。

修改后的代码片段如下:

<table>
<c:if test="${testruns.employeecase != null}">
<tr><th colspan="2" class="labelOnLeft">
<label class="labelOnLeft">
<html:checkbox name="testruns" indexed="true" property="selectedCheckbox" />
<bean:write name="testruns" property="label" /> - <bean:write name="testruns" property="employeecase" />
<c:if test="${testruns.testAvailable}"><span style="color: red;">Test Available</span></c:if></label>
<html:hidden name="testruns" indexed="true" property="label" /></th></tr>

说明

  • 内联CSS的style="color: red;"只会作用于<span>包裹的"Test Available"文本,不会影响<label>内的其他元素
  • 原有的<c:if>标签逻辑完全保留,仅对条件成立时输出的内容做样式包裹

内容的提问来源于stack exchange,提问作者Tan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 07:52:35