标题:js如何实现变色的同时选中复选框
取消只看楼主
apple2683
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-10-30
 问题点数:0 回复次数:0 
js如何实现变色的同时选中复选框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>001</title>
</head>
<body>
<center>
<table id="senfe">
<tr>
<th>选择</th><th>姓名</th><th>性别</th><th>民族</th><th>电话</th>
</tr>

<tr>
<td><input type='checkbox' id='checkbox[]' name='checkbox[]'></td>
<td>1</td><td>2</td><td>3</td><td>4</td>
</tr>

<tr>
<td><input type='checkbox' id='checkbox[]' name='checkbox[]'></td>
<td>1</td><td>2</td><td>3</td><td>4</td>
</tr>

<tr>
<td><input type='checkbox' id='checkbox[]' name='checkbox[]'></td>
<td>1</td><td>2</td><td>3</td><td>4</td>
</tr>

<tr>
<td><input type='checkbox' id='checkbox[]' name='checkbox[]'></td>
<td>1</td><td>2</td><td>3</td><td>4</td>
</tr>

<tr>
<td><input type='checkbox' id='checkbox[]' name='checkbox[]'></td>
<td>1</td><td>2</td><td>3</td><td>4</td>
</tr>
</table>
</center>



<script language="javascript">
senfe("senfe","#E0E0E0","#ccc","#2894FF","#02F78E");   //senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
function senfe(o,a,b,c,d){ //隔行变色的同时,鼠标滑过和点击都会变色
var t=document.getElementById(o).getElementsByTagName("tr");   
for(var i=0;i<t.length;i++){
    t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b;
    t[i].onclick=function(){
       if(this.x!="1"){
        this.x="1";
        this.style.backgroundColor=d;
        
       }else{
        this.x="0";
        this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
       }
      }
      t[i].onmouseover=function(){
       if(this.x!="1")this.style.backgroundColor=c;
      }
      t[i].onmouseout=function(){
       if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
      }
    }
    }
</script>

</body>
</html>
搜索更多相关主题的帖子: html content PUBLIC center 
2011-10-30 15:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-353835-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.967986 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved