日期:2014-05-16 浏览次数:20430 次
<style>
table{ border-collapse:collapse; }
td{border:1px solid #000; padding:5px }
</style>
<table id="tbhead" bgcolor="#aaaaff" >
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
<table id="tb1" >
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
</table>
<script language="javascript">
var tbhead = document.getElementById('tbhead');
var oTab = document.getElementById('tb1');
var rs= oTab.rows,cIdx ;
tbhead.onclick=function(evt){
var el=window.event?event.srcElement:evt.target;
if(el.tagName!='TD'
------解决方案--------------------
el.cellIndex==cIdx ) return;
//console.info( el.cellIndex )
cIdx=cIdx
------解决方案--------------------
0;
for(var i=0;i<rs.length;i++){
rs[i].cells[cIdx].style.backgroundColor = "#fff";
rs[i].cells[el.cellIndex].style.backgroundColor = i%2?'#88FFFF':'#E0FFFF';
}
cIdx=el.cellIndex;
}
</script>