js语言实现自定义表格+隔行变色
代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>自定义表格+隔行变色</title>
<script>
function table(row,col,t,bgc1,bgc2){
//table、caption、tr、td
document.write('<table border="1" width="600" align="center" cellpadding="0" cellspacing="0">');
document.write('<caption>'+t+'</caption>');
//8行6列
for(var i=0;i<row;i++){
var color;
if(i%2==0){
color=bgc1;
}
else
{
color=bgc2;
}
document.write('<tr bgcolor="'+color+'">');
for(var j=0;j<col;j++){
document.write('<td>1</td>');
}
document.write('</tr>');
}
document.write('</table>');
}
table(8,6,"自定义表格","red","blue");
</script>
</head>
<body>
</body>
</html>