css实现的,用expression但在实际中部建议使用,占用资源而且firefox浏览器不支持 .db tr{ background-color:expression('#000000,#333333,#555555,#777777,#999999,#bbbbbb,#dddddd,#ffffff'.split(',')[rowIndex%8]); } [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 就两颜色的时候可以改这这样 <br>.db tr{ <br>background-color:expression('#abcdef,#123456'.split(',')[rowIndex%2]); <br>} <br> .db { border-collapse:collapse;} .db tr{ background-color:expression('#F8F8F8,#EFEFEF'.split(',')[rowIndex%2]); } [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 如果真想用,可以用下面的js写的 <!-- var colorArr = new Array("#ffffff","#cccccc","#999999","#666666","#333333"); var s = 0; function listDoodle() { var list = document.getElementById("list").getElementsByTagName("tr"); for (var i=0;i<list.length ;i++ ) { list[i].style.backgroundColor = colorArr[s++]; if (s==(colorArr.length-1)) { s = 0; } } } window.onload = listDoodle; //--> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] <!-- var colorArr = new Array("#ffffff","#cccccc","#999999","#666666","#333333"); var s = 0; function listDoodle() { var list = document.getElementById("list").getElementsByTagName("tr"); for (var i=0;i<list.length ;i++ ) { list[i].style.backgroundColor = colorArr[s++]; if (s==(colorArr.length-1)) { s = 0; } } } window.onload = listDoodle; //-->