隔行变色,高亮显示

55 篇文章 0 订阅

隔行变色,高行显示

CSS部分

	#box {
		margin: 100px auto;
		width: 400px;
		height: 200px;
	}
	table {
		border-collapse: collapse;
		border: 1px solid #ccc;
	}
	table thead th{
		width: 400px;
		height: 40px;
		font: 16px/40px "simsun";
		text-align: center;
		background-color: #06F;
		color: #fff;
		border-left: 1px solid #ccc;
	}
	table tbody tr {
		height: 37px;
		width:400px;
		font: 15px/37px "simsun";
		text-align: center;
		border-top: 1px solid #ccc;
		cursor: pointer;
	}
	table tbody tr td{
		border: 1px solid #ccc;
	}

body部分

<div id="box">
	<table>
		<thead>
			<tr>
				<th>姓名</th>
				<th>语文</th>
				<th>数学</th>
				<th>英语</th>
			</tr>
		</thead>
		<tbody id="tbody">
			<tr>
				<td>张三</td>
				<td>90</td>
				<td>98</td>
				<td>90</td>
			</tr>
			<tr>
				<td>李四</td>
				<td>92</td>
				<td>99</td>
				<td>88</td>
			</tr>
			<tr>
				<td>王五</td>
				<td>91</td>
				<td>94</td>
				<td>92</td>
			</tr>
			<tr>
				<td>赵六</td>
				<td>90</td>
				<td>92</td>
				<td>94</td>
			</tr>
		</tbody>
	</table>
</div>

JavaScript部分

var tbody = documentById("tbody");
var trArr = tbody.getElementsByTagName("tr");
for(var i=0; i<trArr.length; i++){
	if(i%2 !==0){
		trArr[i].style.backgroundColor = "#eee";
	}else{
		trArr[i].style.backgroundColor = "#aaa";
	}
	var color = "";
	trArr[i].onmouseover = function(){
		color = this.style.backgroundColor;
		this.style.backgroundColor = "#fff";
	}
	trArr[i].onmouseout = function(){
		this.style.backgroundColor = color;
	}
}

隔行显示效果
高亮显示

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值