天天看点

js高级隔行变色(移入移出高亮)

<!DOCTYPE html>
<html>
<head>
	<title>高级隔行变色</title>
</head>
<script type="text/javascript">
	window.onload=function(){
    var otb = document.getElementById('tab');
    for(var i=0; i<otb.tBodies[0].rows.length;i++){
        var otable = '';
       otb.tBodies[0].rows[i].onmouseover=function(){
        
         otable = this.style.background;
            this.style.background='red';
       };
          otb.tBodies[0].rows[i].onmouseout=function(){
          this.style.background=otable;
}

		if(i%2==0){
			otb.tBodies[0].rows[i].style.background='grey';
		    }
		else {
          otb.tBodies[0].rows[i].style.background='';
			 }
	}
	};
</script>
<body>


<table border="2" style="text-align: center;" width="600px;" id="tab">
   <thead>
	<tr>
		<th>编号</th>
		<th>姓名</th>
		<th>年龄</th>
	</tr>
</thead>
	<tbody>
		<tr>
			<td>1</td>
			<td>zs</td>
			<td>12</td>
		</tr>
		<tr>
			<td>2</td>
			<td>ls</td>
			<td>32</td>
		</tr>
		<tr>
			<td>3</td>
			<td>ww</td>
			<td>22</td>
		</tr>

	</tbody>


</table>
</body>
</html>
           
js高级隔行变色(移入移出高亮)

继续阅读