【问题标题】:Dynamically changing CSS property when conditional statement is met using JSTL使用 JSTL 满足条件语句时动态更改 CSS 属性
【发布时间】:2016-03-10 10:15:31
【问题描述】:

我的目标是在满足条件时动态更改 if 语句中 HTML 按钮的 CSS 属性。我对它的工作原理有一个简短的了解,但不确定如何更改 JSTL 中的当前 css 属性。

例如

<input type="submit" value="Previous" class="button"/> 
 <c:if test = "condition goes here">
      //change or set css properties here
 </c:if> 

【问题讨论】:

  • 怎么做?
  • 我已经知道 ${...} 代表什么。它只是在该条件内动态更改 css 属性。或者我有类似的例子吗?
  • 一个例子是当满足条件时,我想改变css属性的颜色
  • 我如何在 if 语句中写这个?

标签: html css jstl


【解决方案1】:

如果您愿意,您可以使用内联样式,或者通过这种方式创建新样式标签以更好地实现:

解决方案 1

<input type="submit" value="Previous" class="button" <c:if test = "condition goes here">style="css-style:${yourProp}"</c:if>/>

解决方案 2

<c:if test = "condition goes here">
  <style type='text/css'>
     .button{css-style:${yourProp}}
  </style>
</c:if>
<input type="submit" value="Previous" class="button"/>

使用第二种解决方案最大的问题是样式旁边的所有元素都会采用样式,因此您需要一些 id 或标识符。

【讨论】:

  • 我使用了解决方案 1,效果很好。感谢帮助
猜你喜欢
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
  • 2018-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-01
  • 1970-01-01
相关资源
最近更新 更多