如果是这个来控制表格背景颜色~~
那么原来有背景色的~在鼠标移到这个的时候用的是新的颜色~~~移走要保持原来的颜色怎么办?~~<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>
那么原来有背景色的~在鼠标移到这个的时候用的是新的颜色~~~移走要保持原来的颜色怎么办?~~<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>
解决方案 »
- 怎么判断是ID名还是类名
- 请教: dtree源代码中的函数是怎样被调用的
- 鼠标放上去->详细信息怎么做?
- 如何用JS更改文本框的Enabled的值?急!
- 打开一个新页面如何自动打开这个页面上的链接。
- 下面这段代码在IE和netscape4.8中都能够实现图片的拖拉移动,为什么到了netscape7.0中就不能实现呢
- histoy.back问题
- 如何在文本框中分别验证“汉字”和“英文字符串”的长度,有高分哦!!
- 一个列表框中有几个选项,现在我想改变某一个选项的字体颜色,请问应该怎样做?
- 建立飞船打陨石类游戏的框架:包括html代码和陨石的js框架
- 关于js与gridview
- iframe添加事件问题
<table id="tab">
<tr><td>xx</td></tr>
<tr><td>xx</td></tr>
<tr><td>xx</td></tr>
</table>
<script type="text/javascript">
var t=document.getElementById("tab");
var tr=t.rows;
var bg=bg1=null;
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}
bg = tr[n].style.background;
bg1 = tr[n+1].style.background;
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=bg;
tr[n+1].style.background=bg1;
}
</script>
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<table id="tab">
<tr style="background-color: blue;">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr style="background-color: yellow;">
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr style="background-color: green;">
<td>x</td>
<td>y</td>
<td>z</td>
</tr>
</table>
<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 == tr.length-1) n--;
tr[n].style.originalBgColor = tr[n].style.backgroundColor;
tr[n+1].style.originalBgColor = tr[n+1].style.backgroundColor; tr[n].style.backgroundColor = '#F00';
tr[n+1].style.backgroundColor = '#F00';
}
function r(n)
{
if(n == tr.length-1) n--; tr[n].style.backgroundColor = tr[n].style.originalBgColor;
tr[n+1].style.backgroundColor = tr[n+1].style.originalBgColor;
}
</script>
</body>
</html>