1.首先,在CSS文件中定义要设置的颜色。比如,
.resetrowscolor {
background-color: red; }2.在要显示的页面中引入该CSS文件,比如
<link href="./resources/css/cdaxsl.css" rel="stylesheet" type="text/css" />
3.在JS中定义设置颜色的function:
function resetRowsColor(tableName)
{ var myTable = document.getElementById(tableName); for (var i = 1; i < myTable.rows.length; i++) { myTable.rows[i].className = 'resetrowscolor'; } }然后在需要设置Table行颜色的地方调用它,比如:
resetRowsColor("childexam"); //ChildExam为要设置的table id