如何设置表格奇偶行不同颜色鼠标划过变色的javascript代码?
如何设置表格奇偶行不同颜色鼠标划过变色的javascript代码?
<script language="javascript">
function tr_onmouseover(){
eval("this.style.backgroundColor='#EFEFEF';");
}
function tr_onmouseout_grey(){
eval("this.style.backgroundColor='#F9F9F9';");
}
function tr_onmouseout_white(){
eval("this.style.backgroundColor='#FFFFFF';");
}
function document_onload(){
var i;
for(i=0;i<tlist.rows.length;i++){
if(i%2==0){
tlist.rows( i ).style.backgroundColor="#F9F9F9";
tlist.rows( i ).onmouseout=tr_onmouseout_grey;
}
else{
tlist.rows( i ).onmouseout=tr_onmouseout_white;
}
tlist.rows( i ).onmouseover=tr_onmouseover;
}
}
</script>
将以上代码添加在<head>之间,将要设定的表格中添加<table id="tlist">即可