鼠標經過改變表格背景屬性實例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
<style type="text/css">
.tab table
{ border-collapse:collapse; width:500px;}
.tab td
{ border:1px solid #999; height:26px;}
</style>
</head>

<body>
<div  class="tab">
<table width="100%" cellspacing="0" cellpadding="0" id="tab">
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
</table>
</div>
<script type="text/javascript">
var t=document.getElementById("tab");
var tr=t.rows;
for(i=0;i<tr.length;i++){
tr[i].onmouseover
=Function("c("+i+")");
tr[i].onmouseout
=Function("r("+i+")");
}
function c(n){
   
if(n+1>tr.length-1){n=n-1}
    tr[n].style.background
='#F00';
    tr[n
+1].style.background='#F00';
}
function r(n){
   
if(n+1>tr.length-1){n=n-1}
    tr[n].style.background
='none';
    tr[n
+1].style.background='none';
}
</script>
</body>
</body>
</html>

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
<style type="text/css">
.tab table
{ border-collapse:collapse; width:500px;}
.tab td
{ border:1px solid #999; height:26px;}
</style>
</head>

<body>
<div  class="tab">
<table width="100%" cellspacing="0" cellpadding="0" id="tab">
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
 
<tr>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
   
<td>&nbsp;</td>
 
</tr>
</table>
</div>
<script type="text/javascript">
var t=document.getElementById("tab");
var tr=t.rows;
for(i=0;i<tr.length;i++){
tr[i].onmouseover
=Function("c("+i+")");
tr[i].onmouseout
=Function("r("+i+")");
}
function c(n){
   
if((n)%2!=0){n=n-1}
    tr[n].style.background
='#F00';
    tr[n
+1].style.background='#F00';
}
function r(n){
   
if((n)%2!=0){n=n-1}
    tr[n].style.background
='none';
    tr[n
+1].style.background='none';
}
</script>
</body>
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章