【问题标题】:how can i change the color of rows using jquery? based on conditions如何使用 jquery 更改行的颜色?根据条件
【发布时间】:2017-03-17 11:02:55
【问题描述】:
 <tr class="acti">//class 
<script type="text/javascript">
  var status =  $(this).parent().parent().children(".activity-status").attr("data-value");//Jquery value according to which the colour of the upper class is going to be changed

我使用 for each 循环显示结果,因此状态值会发生变化,我想根据值更改颜色,例如如果状态 == 1,则类的颜色为红色,当它为 2 时颜色更改变绿

【问题讨论】:

  • 你能用html表结构粘贴一个jsfiddle吗?
  • $(this) 中有什么对象存储?

标签: jquery html css asp.net-mvc


【解决方案1】:

我们开始吧:

var status =  $(this).parent().parent().children(".activity-status").attr("data-value");

if(status == 1){
    $("tr").css("color","yourcolor");
}
else if(status == 2){
    $("tr").css("color","anothercolor");
}

【讨论】:

  • 我已经完成了,但它正在获取记录列表的第一个值
  • 你的意思是第一行?
  • 只是第一个
  • 然后写:$("tr:first").css("color","yourcolor");$("table tr:first").css("color","yourcolor");
猜你喜欢
  • 1970-01-01
  • 2013-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-16
相关资源
最近更新 更多