两种方法点其他地方选择checkbox

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值