2013-07-26 17 views
0

我正在开发ASP.NET MVC应用程序。它具有使用表格显示每月数字的功能。根据季度显示,它是动态创建的。每月显示为
第-1周-2周-3周-4就是这样。这个名字显示在表头部分。
对于每个月显示为不同颜色的背景,我已经实现了显示这些东西。现在它显示颜色表格标题。我的问题是我如何将这个背景颜色应用到表格tds?它应该以coloumnwise显示。我将使用JQuery。
例如:
如果coloumn头一个是红色的每列td应该是背景颜色相同。我如何使用JQuery将表格标题颜色应用到表格主体

编辑:这里是jsfiddle.net/ucfs8/ 我试图插入的jsfiddle显示错误请到该链接的jsfiddle

编辑编辑:解决方案是OKIs有没有办法做到这一点使用CSS只是因为JQuery在钻取应用程序时速度很慢。实际上,这基于树结构。当你点击节点时,它会向下钻取到子节点。一个节点有大约10个子节点。然后花时间使用JQuery加载。谢谢。

+0

您已经尝试的jsfiddle? – falguni

+0

为什么选择jQuery?为什么不只是CSS? – melancia

+0

你正在使用网格视图? – rps

回答

1

如果您自己生成表格,只需添加一个co l组对它和风格。

喜欢的东西(jsFiddle example):

<colgroup> 
     <col style="width: 3%; background-color: whitesmoke" /> 
     <col style="width: 10%; background-color: whitesmoke" /> 
     <col style="width: 11%; background-color: whitesmoke" /> 
     <col style="background-color:#ebcccc" /> 
     <col style="background-color:#ebcccc" /> 
     <col style="background-color:#ebcccc" /> 
     <col style="background-color:#ebcccc" /> 
     <col style="background-color:#dff0d8" /> 
     <col style="background-color:#dff0d8" /> 
     <col style="background-color:#dff0d8" /> 
     <col style="background-color:#dff0d8" /> 
     <col style="background-color:#dff0d8" /> 
     <col style="background-color:#d9edf7" /> 
     <col style="background-color:#d9edf7" /> 
     <col style="background-color:#d9edf7" /> 
     <col style="background-color:#d9edf7" /> 
     <col style="background-color:#d0e9c6" /> 
     <col style="background-color:#d0e9c6" /> 
     <col style="background-color:#d0e9c6" /> 
     <col style="background-color:#d0e9c6" /> 
     <col style="background-color:#d0e9c6" /> 
     <col/> 
</colgroup> 

理想情况下,你会使用一些CSS类:d

+0

很好的解决方案谢谢..最后我没有使用jquery – unique

3

如果你能找到至极列的兴趣,你应该很容易:

$(document).ready(function() { 
    var color = $("table>thead th").css("background-color") 
    $("table>tbody td").css("background-color", color) 
} 

您可以使用多个子选择器中选择每一列,是这样的:

for(...length){ 
    var color = $("table>thead th:nth-child(1)").css("background-color"); 
    $("table>tbody td:nth-child(1)").css("background-color", color) 
} 
1

入住这里, UPDATE DEMO http://jsfiddle.net/yeyene/ucfs8/2/

$(document).ready(function() { 
    var col = $('table tr td'); 
    $('table tbody tr').each(function() { 
     $(this).css('background-color','whitesmoke'); 
     for (var i = 0; i <= col.length; i++) { 
      var color = $('table th').eq(i).css('background-color'); 
      $(this).find('td').eq(i).css('background-color', color); 
     } 
    }); 
}); 
+0

非常感谢你 – unique

+1

不客气。 – yeyene

+0

我们可以使用CSS来做到这一点吗? – unique

相关问题