码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript实例---表格隔行变色以及移入鼠标高亮

时间:2015-05-16 10:28:50      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>index</title>
<style type="text/css">
	#div1{width: 100px;height:100px;background: red;}
</style>
<script type="text/javascript">
window.onload = function()
{
	var oTab = document.getElementById(‘tab1‘);
	var oldColor = ‘‘;
	for(var i=0;i<oTab.tBodies[0].rows.length;i++)
	{
		oTab.tBodies[0].rows[i].onmouseover = function()
		{
			oldColor = this.style.background;
			this.style.background = "green";
		}
		oTab.tBodies[0].rows[i].onmouseout = function()
		{
			this.style.background = oldColor;
		}
		if(i%2)
		{
			oTab.tBodies[0].rows[i].style.background = ‘red‘;
		}
		else
		{
			oTab.tBodies[0].rows[i].style.background= " ";
		}
	}
}

</script>
</head>
<body>
	<table border="1" width="300" id="tab1">
		<thead>
			<td>ID</td>
			<td>NAME</td>
			<td>AGE</td>
		</thead>
		<tbody> 
			<tr>
				<td>1</td>
				<td>John</td>
				<td>27</td>
			</tr>
			<tr>
				<td>2</td>
				<td>Lucy</td>
				<td>27</td>
			</tr>
			<tr>
				<td>3</td>
				<td>Dan</td>
				<td>26</td>
			</tr>
			<tr>
				<td>4</td>
				<td>Ben</td>
				<td>30</td>
			</tr>
		</tbody>
	</table>
</body>
</html>

  

JavaScript实例---表格隔行变色以及移入鼠标高亮

标签:

原文地址:http://www.cnblogs.com/zsboy/p/4507440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!