简体   繁体   English

使用 JSTL 在满足条件语句时动态更改 CSS 属性

[英]Dynamically changing CSS property when conditional statement is met using JSTL

I am aiming to dynamically change CSS properties of a HTML button inside an if statement, when the condition is met.我的目标是在满足条件时动态更改 if 语句中 HTML 按钮的 CSS 属性。 I have a brief idea on how it would work but not sure on how you would change the current css property in JSTL.我对它如何工作有一个简短的想法,但不确定如何更改 JSTL 中的当前 css 属性。

For example例如

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

You can use inline style if you want or make a better implementation creating a new style tag in this way:如果需要,您可以使用内联样式,或者以这种方式创建新样式标签的更好实现:

Solution 1解决方案1

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

Solution 2解决方案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"/>

with the second solution the big problem is that all the elements next to the style will take the style, so you need some id or identifier.使用第二种解决方案,最大的问题是样式旁边的所有元素都将采用样式,因此您需要一些 id 或标识符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM