87,992
社区成员
发帖
与我相关
我的任务
分享<table>
<tr><td>1</td><td>2</td></tr>
</table>
<script>
var t = document.getElementsByTagName("td");
for (var i=0;i<t.length ;i++ )
{
t[i].onmouseover = function(){
this.style.background="red";
}
t[i].onmouseout = function(){
this.style.background="";
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
</style>
</head>
<body>
<table style="width:500px;" border="1">
<tr>
<td>1111</td>
</tr>
<tr>
<td>1111</td>
</tr>
<tr>
<td>1111</td>
</tr>
<tr>
<td>1111</td>
</tr>
</table>
<script>
var trs = document.getElementsByTagName('tr');
for(var i = 0,tr; tr = trs[i++];){
tr.onmouseover = function(){
this.style.background = '#333';
};
tr.onmouseout = function(){
this.style.background = '#fff';
};
}
</script>
</body>
</html>
<html>
<head>
<title>表格变色</title>
<style type="text/css">
.odd{background:#ffffee;}
.even{background:#fff38f;}
.first{background:red;}
.last{background:blue;}
.mouseOver{background:green;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("tr:odd").addClass("odd"); //加奇行样式
$("tr:even").addClass("even"); //加偶行样式
$("tr:first").addClass("first"); //为第一行加样式
$("tr:last").addClass("last"); //为最后行加样式
//为行元素加上鼠标移入和移出事件
$("tr").mouseover(function() {
$(this).addClass("mouseOver") //加上样式
}).mouseout(function() {
$(this).removeClass("mouseOver")//去掉样式
});
})
</script>
</head>
<body>
<table border="1">
<tr><td>姓名</td><td>年龄</td></tr>
<tr><td>王华</td><td>18</td></tr>
<tr><td>刘云</td><td>19</td></tr>
<tr><td>刘亮</td><td>15</td></tr>
<tr><td>叶子</td><td>17</td></tr>
<tr><td>刘梦</td><td>20</td></tr>
</table>
</body>
</html>