javascript实现GridView单击行变色

function SetBGChange()
{
    var c;
    var d;
    var obj = document.getElementById("ctl00_ContentPlaceHolder1_GridView1").getElementsByTagName("tr");
    for(var i=1; i<obj.length; i++)
    {
        obj[i].onmouseover=function()
        {
            c=this.style.backgroundColor;
            d=this.style.backgroundColor;
            this.style.backgroundColor='#fffce0'; //鼠标移上
        }
        obj[i].onmouseout=function()
        {
            this.style.backgroundColor = c == "#dddddd" ? "#dddddd" : "#f8f8f8"; //鼠标离开
        }
        obj[i].onclick=function()
        {
            d = d == "#dddddd" ? "#f8f8f8" : "#dddddd"; //调整将当前行背景色
            this.style.backgroundColor = d;
            c=this.style.backgroundColor;
        }
    }
}

if(window.attachEvent)
  window.attachEvent("onload",SetBGChange);

posted @ 2009-01-07 09:33  jay-c  阅读(488)  评论(0)    收藏  举报