Home >Web Front-end >JS Tutorial >Solution to table interlaced color change in IE8 chrome_javascript skills

Solution to table interlaced color change in IE8 chrome_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:23:321085browse

For version codes above IE8, only CSS is required
tr{ background-color:expression('#F8F8F8,#EFEFEF'.split(',')[rowIndex%2]); }
For below IE8 The version code requires CSS and JS to be completed together:
First define two CSSs, the code is as follows:

Copy code The code is as follows:

.tr1{background-color:#fff;}
.tr2{background-color:#00ff;}

Actually write JS Code, the code is as follows:
Copy code The code is as follows:

onload=function(){
var trs=document.getElementById("tbid").getElementsByTagName("tr");//Get all tr ​​information in the table of tbid
for(var i=0;i{
 if(i%2==0)
trs[i].className="tr1";
else
trs[i].className="tr2";
}
}

Author: chenhuzi
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn