版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan
<!-- 点td选checkbox,顺便背景变颜色,加强版 -->
<script type="text/javascript" src=""></script>
<script type="text/javascript">
//判断浏览器类型
function getOs()
{
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";
}
}
function tdcheckbox(tr)
{
if(getOs()=="MSIE")
{
var me =event.srcElement;
if(me.tagName != "INPUT") {
var me = tr.firstChild.firstChild;
me.checked = !me.checked;
}
tr.style.backgroundColor = me.checked ? "blue" : "";
}
}
</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>
<meta http-equiv="Content-Language" content="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="马永占(MyZ)" />
<meta name="Copyright" content="马永占(MyZ)" />
<meta name="description" content="" />
<meta name="keywords"content="" />
<link rel="icon" href="" type="image/x-icon" />
<link rel="shortcut icon" href="" type="image/x-icon" />
<link href="" rel="stylesheet" type="text/css" />
<title></title>
<style type="text/css">
<!--
-->
</style>
</head>
<body>
<table>
<tr οnclick="tdcheckbox(this)">
<td><input id="1" type="checkbox" name="a"></td><td>123</td>
</tr>
<tr οnclick="tdcheckbox(this)">
<td><input id="2" type="checkbox" name="b"></td><td>456</td>
</tr>
</table>
</body>
</html>
<!-- 点td选checkbox,顺便背景变颜色 -->
<script type="text/javascript" src=""></script>
<script type="text/javascript">
//判断浏览器类型
function getOs()
{
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";
}
}
function tdcheckbox(tr)
{
if(getOs()=="MSIE")
{
var me = event.srcElement;
if(event.srcElement.tagName!="INPUT"){
var a = tr.getElementsByTagName("INPUT");
for(var i=0; i<a.length; i++){
if(a[i].name == "a"){
a[i].checked=!a[i].checked;me=a[i];
break;
}
}
}
tr.style.backgroundColor = me.checked ? "red" : "";
}
}
</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>
<meta http-equiv="Content-Language" content="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="马永占(MyZ)" />
<meta name="Copyright" content="马永占(MyZ)" />
<meta name="description" content="" />
<meta name="keywords"content="" />
<link rel="icon" href="" type="image/x-icon" />
<link rel="shortcut icon" href="" type="image/x-icon" />
<link href="" rel="stylesheet" type="text/css" />
<title></title>
<style type="text/css">
<!--
-->
</style>
</head>
<body>
<table border="1" width="200">
<tr
οnclick="tdcheckbox(this)">
<td><input id="1" type="checkbox" name="a"></td><td>123</td>
</tr>
<tr
οnclick="tdcheckbox(this)">
<td><input id="2" type="checkbox" name="a"></td><td>456</td>
</tr>
</table>
</body>
</html>