jquery隔行变色 跨行了怎么办啊!
2个回答
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>MODEL PAGE</title>
<style type="text/css">
TABLE {
border-collapse: collapse;
border: 1px solid black;
}
TD {
border: 1px solid black;
}
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$ (function ()
{
$ ('tr').css ("background-color", "red");
$ ('tr').each (function (i, dom)
{
var isRowSpan = $ (this).is (function ()
{
return $ ('td[rowspan]', this).length > 0;
});
if (isRowSpan)
{
var count = $ (this).find ('td[rowspan]').prop ('rowspan');
$ (this).nextAll ('tr:lt(' + (count - 1) + ')').andSelf ().css ("background-color", "green");
}
});
});
</script>
</head>
<body>
<table width="100%" border="1">
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
<td rowspan="3">$50</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td>February</td>
<td>$60</td>
</tr>
</table>
</body>
</html>
展开全部
给偶数行的数据背景色
$("tr:even").css('background-color','red');
给奇数行背景色
$("tr:odd").css('background-color','green');
$("tr:even").css('background-color','red');
给奇数行背景色
$("tr:odd").css('background-color','green');
追问
不行的啊,跨行的不行!even、odd方法我早就试了.....用rowspan跨行了的弄不出来我要的效果......
追答
用样式试试css3:
<style>
table tr:nth-child(odd){background:#F4F4F4;}
table tr:nth-child(even){background:#C00;}
</style>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询