JS单双色表格

//id,颜色a,颜色b
function DColorTable(tid, colora, colorb)
{
	var ctrl = document.getElementById(tid);
	if(ctrl==null)return;
	
	var trs = ctrl.getElementsByTagName("tr");
	
	for ( var i = 0; i < trs.length; i++)
	{
		trs[i].style.backgroundColor = (trs[i].sectionRowIndex % 2 == 0) ? colora : colorb;
	}
}

DColorTable("dcolorTable","#FFFFFF","#c6e1fd");

Comments are closed.