zoukankan      html  css  js  c++  java
  • Gridview------Set BackgroundColor

    <head id="Head1" runat="server">
        <title>Gridview------Set BackgroundColor</title>
        <link href="~/CSS/Gridview.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript">
            //把事件放在onload里,
            //使用&lt;%=%>方式输出GridView的ID是因为某些情况下(如使用了MasterPage)会造成HTML中ID的变化
            //颜色值推荐使用Hex,如 #f00 或 #ff0000
            window.onload = function(){
                GridViewColor("<%=GridView1.ClientID%>","#fff","#eee","#6df","#fd6");
            }
            
            //参数依次为(后两个如果指定为空值,则不会发生相应的事件):
            //GridView ID, 正常行背景色,交替行背景色,鼠标指向行背景色,鼠标点击后背景色
            function GridViewColor(GridViewId, NormalColor, AlterColor, HoverColor, SelectColor){
                //获取所有要控制的行
                var AllRows = document.getElementById(GridViewId).getElementsByTagName("tr");
                
                //设置每一行的背景色和事件,循环从1开始而非0,可以避开表头那一行
                for(var 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>
    </head>
  • 相关阅读:
    Oracle 归档模式
    如果在安装32位Oracle客户端组件的情况下64位模式运行, 将出现此问题.
    ORA-00972: 标识符过长
    Oracle SQL%ROWCOUNT
    ASP.NET Core 中间件的几种实现方式
    Python 闭包
    Python 迭代器
    Python 正则表达式提高
    Python正则表达式
    Python 生成器
  • 原文地址:https://www.cnblogs.com/YoungPop-Chen/p/3277448.html
Copyright © 2011-2022 走看看