列变色
不多说了,看Demo 吧
感觉没用上,先放在这里,备个份
感觉没用上,先放在这里,备个份
<script>
function cells_color(){
var oColor,td=event.srcElement
if(td.tagName!="TD") //如果事件不是发生在单元格上,退出函数
return
if(event.type=="mouseover") //判断事件类型,决定单元格改变的颜色
oColor="#dedede"
else oColor="#ffffff"
//依次捕获的对象为 td.tr.tbody.table.colgroup单元格的上两级对象为表格
cols=td.parentElement.parentElement.parentElement.children[0]
cols.children[td.cellIndex].style.backgroundColor=oColor
}
</script>
<table width="200" height="30" border="1" onmouseover="cells_color()" onmouseout="cells_color()">
<col><col><col>
<tr>
<td>demo</td>
<td>demo</td>
<td>demo</td>
</tr>
<tr>
<td>demo</td>
<td>demo</td>
<td>demo</td>
</tr>
<tr>
<td>demo</td>
<td>demo</td>
<td>demo</td>
</tr>
</table>
function cells_color(){
var oColor,td=event.srcElement
if(td.tagName!="TD") //如果事件不是发生在单元格上,退出函数
return
if(event.type=="mouseover") //判断事件类型,决定单元格改变的颜色
oColor="#dedede"
else oColor="#ffffff"
//依次捕获的对象为 td.tr.tbody.table.colgroup单元格的上两级对象为表格
cols=td.parentElement.parentElement.parentElement.children[0]
cols.children[td.cellIndex].style.backgroundColor=oColor
}
</script>
<table width="200" height="30" border="1" onmouseover="cells_color()" onmouseout="cells_color()">
<col><col><col>
<tr>
<td>demo</td>
<td>demo</td>
<td>demo</td>
</tr>
<tr>
<td>demo</td>
<td>demo</td>
<td>demo</td>
</tr>
<tr>
<td>demo</td>
<td>demo</td>
<td>demo</td>
</tr>
</table>
学习,积累中......