随笔-1  评论-2  文章-2  trackbacks-0

最新评论

Re:GridView隔行变色方法 宋华 2011-07-18 18:04  
<script type="text/javascript"> //GridView ID, 正常行背景色,交替行背景色,鼠标指向行背景色,鼠标点击后背景色   function GridViewColor(GridViewId, NormalColor, AlterColor, HoverColor, SelectColor) { var AllRows = document.getElementById(GridViewId).getElementsByTagName( "tr" ); //设置每一行的背景色和事件,循环从1开始而非0,可以避开表头那一行 for (i = 1; i < AllRows.length; i++) { AllRows[i].style.background = i % 2 == 0 ? NormalColor : AlterColor; //如果指定了鼠标指向的背景色,则添加onmouseover/onmouseout事件    //处于选中状态的行发生这两个事件时不改变颜色    if(HoverColor != "")    {    AllRows[i].onmouseover = function(){if(!this.selected)this.style.background = HoverColor;}    if(i%2 == 0)    {    AllRows[i].onmouseout = function(){if(!this.selected)this.style.background = NormalColor;}    }    else    {    AllRows[i].onmouseout = function(){if(!this.selected)this.style.background = AlterColor;}    }    } //如果指定了鼠标点击的背景色,则添加onclick事件    //在事件响应中修改被点击行的选中状态    if(SelectColor != "")    {    AllRows[i].onclick = function()    {    this.style.background = this.style.background==SelectColor?HoverColor:SelectColor;    this.selected = !this.selected;    }    } } } </script> 调用: <body onload='GridViewColor("GridView1","#ffa","#bbb","#6df","#fd6")'>
Re:GridView隔行变色方法 mytot 2009-08-06 15:19  
这不叫隔行变色,这是鼠标停留变色