61,116
社区成员
发帖
与我相关
我的任务
分享
<!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>dhtml.table.changeTrBgColor.html</title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<h3>选中行变色!注:IE6ps1, FF2 测试可用!</h3>
<table width="590" height="61" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="280">
<input type="checkbox" name="cbxGroup" value="checkbox" />
<label>aaa</label></td>
<td width="304"> </td>
</tr>
<tr>
<td>
<input type="checkbox" name="cbxGroup" value="checkbox" />
<label>bbb</label></td>
<td> </td>
</tr>
</table>
</body>
<script type="text/javascript">
<!--
var aCbx = document.getElementsByName("cbxGroup");
var oTr;
for (var i=0; i<aCbx.length; i++)
{
oTr = aCbx[i].parentNode.parentNode;
// 鼠标经过表格,表格变红色,鼠标离开,表格白色.
oTr.onmouseover = function()
{
this.style.backgroundColor = "pink";
};
oTr.onmouseout = function()
{
this.style.backgroundColor = "white";
};
// 鼠标点击表格,复选框选中,表格变蓝色。
// 鼠标离开后,表格还是蓝色。再次点击表格,复选框不选中,表格变为鼠标经过时的红色。
oTr.checkBox = aCbx[i];
oTr.onclick = function()
{
with (this)
{
checkBox.checked = !checkBox.checked;
if (checkBox.checked)
{
style.backgroundColor = "yellow";
fpMouseover = onmouseover;
onmouseover = null;
fpMouseout = onmouseout;
onmouseout = null;
}
else
{
style.backgroundColor = "pink";
onmouseover = fpMouseover;
onmouseout = fpMouseout;
}
}
};
aCbx[i].onclick = function()
{
this.checked = !this.checked;
};
}
//-->
</script>
</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>
<title>dhtml.table.changeTrBgColor.html</title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<h3>选中行变色!注:IE6ps1, FF2 测试可用!</h3>
<table id="tbeTest" width="590" height="61" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="280">
<input type="checkbox" name="cbxGroup" value="checkbox" />
<label>aaa</label></td>
<td width="304"> </td>
</tr>
<tr>
<td>
<input name="cbxGroup" type="checkbox" value="checkbox" />
<label>bbb</label></td>
<td> </td>
</tr>
</table>
</body>
<script type="text/javascript">
<!--
// 鼠标经过表格,表格变红色,鼠标离开,表格白色.
var oTbe = document.getElementById("tbeTest");
for (var i=0; i<oTbe.rows.length; i++)
{
oTbe.rows[i].onmouseover = function()
{
this.style.backgroundColor = "pink";
};
oTbe.rows[i].onmouseout = function()
{
this.style.backgroundColor = "white";
};
}
// 鼠标点击表格,复选框选中,表格变蓝色。
// 鼠标离开后,表格还是蓝色。再次点击表格,复选框不选中,表格变为鼠标经过时的红色。
var aCbx = document.getElementsByName("cbxGroup");
for (var i=0; i<aCbx.length; i++)
{
aCbx[i].parentNode.checkBox = aCbx[i];
aCbx[i].parentNode.onclick = function()
{
this.checkBox.checked = !this.checkBox.checked;
with (this.parentNode)
{
if (this.checkBox.checked)
{
style.backgroundColor = "yellow";
fpMouseover = onmouseover;
onmouseover = null;
fpMouseout = onmouseout;
onmouseout = null;
}
else
{
style.backgroundColor = "pink";
onmouseover = fpMouseover;
onmouseout = fpMouseout;
}
}
};
aCbx[i].onclick = function()
{
this.checked = !this.checked;
};
}
//-->
</script>
</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>
<title>dhtml.table.changeTrBgColor.html</title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<table id="tbeTest" width="590" height="61" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="280">
<input type="checkbox" name="cbxGroup" value="checkbox" />
<label>aaa</label></td>
<td width="304"> </td>
</tr>
<tr>
<td>
<input name="cbxGroup" type="checkbox" value="checkbox" />
<label>bbb</label></td>
<td> </td>
</tr>
</table>
</body>
<script type="text/javascript">
<!--
// 鼠标经过表格,表格变红色,鼠标离开,表格白色.
var oTbe = document.getElementById("tbeTest");
for (var i=0; i<oTbe.rows.length; i++)
{
with (oTbe.rows[i])
{
onmouseover = function()
{
this.style.backgroundColor = "pink";
};
onmouseout = function()
{
this.style.backgroundColor = "white";
};
}
}
// 鼠标点击表格,复选框选中,表格变蓝色。
// 鼠标离开后,表格还是蓝色。再次点击表格,复选框不选中,表格变为鼠标经过时的红色。
var aCbx = document.getElementsByName("cbxGroup");
for (var i=0; i<aCbx.length; i++)
{
with (aCbx[i])
{
parentNode.onclick = function()
{
this.firstChild.checked = !this.firstChild.checked;
with (this.parentNode)
{
if (this.firstChild.checked)
{
style.backgroundColor = "yellow";
fpMouseover = onmouseover;
onmouseover = null;
fpMouseout = onmouseout;
onmouseout = null;
}
else
{
style.backgroundColor = "pink";
onmouseover = fpMouseover;
onmouseout = fpMouseout;
}
}
};
onclick = function()
{
this.checked = !this.checked;
};
}
}
//-->
</script>
</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>
<title>dhtml.table.changeTrBgColor.html</title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<table id="tbeTest" width="590" height="61" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="280">
<input type="checkbox" name="cbxGroup" id="cbx1" value="checkbox" />
<label for="cbx1">aaa</label></td>
<td width="304"> </td>
</tr>
<tr>
<td>
<input name="cbxGroup" type="checkbox" id="cbx2" value="checkbox" />
<label for="cbx2">bbb</label></td>
<td> </td>
</tr>
</table>
</body>
<script type="text/javascript">
<!--
// 鼠标经过表格,表格变红色,鼠标离开,表格白色.
var oTbe = document.getElementById("tbeTest");
for (var i=0; i<oTbe.rows.length; i++)
{
with (oTbe.rows[i])
{
onmouseover = function()
{
this.style.backgroundColor = "pink";
};
onmouseout = function()
{
this.style.backgroundColor = "white";
};
}
}
// 鼠标点击表格,复选框选中,表格变蓝色。
// 鼠标离开后,表格还是蓝色。再次点击表格,复选框不选中,表格变为鼠标经过时的红色。
var aCbx = document.getElementsByName("cbxGroup");
for (var i=0; i<aCbx.length; i++)
{
with (aCbx[i])
{
onclick = function()
{
with (this.parentNode.parentNode)
{
if (this.checked)
{
style.backgroundColor = "yellow";
fpMouseover = onmouseover;
onmouseover = null;
fpMouseout = onmouseout;
onmouseout = null;
}
else
{
style.backgroundColor = "pink";
onmouseover = fpMouseover;
onmouseout = fpMouseout;
}
}
};
}
}
//-->
</script>
</html>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.1.pack.js"></script>
<script>
//根据你描述的,写了一下 ,还不知道是否你想要的 ,不行你自己看着修改下吧。。。
$(document).ready(function(){
//鼠标经过
$("table tr td").mouseover(function(){
if($(this).find("input[@type=checkbox][@checked]").length == 0)
{
$(this).css("background-color" ,"red");
}
});
//鼠标离开
$("table tr td").mouseout(function(){
if($(this).find("input[@type=checkbox][@checked]").length == 0)
{
$(this).css("background-color" ,"#ffffff");
}
});
//鼠标点击
$("table tr td").click(function(){
if($(this).find("input[@type=checkbox][@checked]").length == 0)
{
$(this).css("background-color" ,"#173CCC");
$(this).find("input[@type=checkbox]").attr("checked" ,true);
}
else
{
$(this).css("background-color" ,"red");
$(this).find("input[@type=checkbox]").attr("checked" ,false);
}
});
});
</script>