• 鼠标指向表格中的一行时,该行背景色改变;点击行时,突出显示标记颜色


    <html>
    <head>
    <script language=javascript>
    /************************************************************************
     *函 数 名:ChangeRowBg(row)
     *功能描述:鼠标指向表格中的一行时,该行背景色改变,点击行时,突出显示标记颜色
     *注:1.在tr中添加事件:onmouseover,onmouseout,onmousedown
     *   2.在tr中如有下载链接(如下载Word文档),请将target设为_blank,否则可能出js错
     *入    参:row--tr对象
     *创 建 人:夏春涛 xchuntao@163.com qq:23106676
     *创建时间:2005-07-01
     ************************************************************************/
      //全局变量
      var OldRowBgColor;
      var NewRowBgColor  = "#b5c5e6"; //用小写
      var MarkRowBgColor = "#ff9933"; //用小写
      function ChangeRowBg(row)
      {
     if (event.type=='mouseover')
     { 
      /*
      RowBgColor = event.srcElement.parentElement.bgColor;   
      event.srcElement.parentElement.bgColor = "#b5c5e6";
      */
      /*
      RowBgColor = event.srcElement.parentElement.style.backgroundColor 
      event.srcElement.parentElement.style.backgroundColor = "#b5e5e6";
      */
      OldRowBgColor = row.style.backgroundColor  
      row.style.backgroundColor = NewRowBgColor

     }
     else if (event.type=='mouseout')
     {
         row.style.backgroundColor = OldRowBgColor;
     }
     else if (event.type=='mousedown')
     {
      if (row.style.backgroundColor != MarkRowBgColor)
      {
       row.style.backgroundColor = MarkRowBgColor;
       row.onmouseout = function(){return false;}
       row.onmouseover= function(){return false;}
         }
         else
         {
       row.style.backgroundColor = NewRowBgColor ;
       row.onmouseout = function(){ ChangeRowBg(row);}
       row.onmouseover= function(){ ChangeRowBg(row);}
         }
     }
      }
    </script>
    </head>
    <body>
    <table align=center width=500 bgcolor="#669999" border=1 cellspacing=0>
    <tr onmouseover="ChangeRowBg(this)" onmouseout="ChangeRowBg(this)" onmousedown="ChangeRowBg(this)" >
    <td>TestData</td>
    <td><a target=_blank href="new.htm">TestLink</td>
    </tr>
    <tr onmouseover="ChangeRowBg(this)" onmouseout="ChangeRowBg(this)" onmousedown="ChangeRowBg(this)" >
    <td>TestData</td>
    <td><a target=_blank href="new.htm">TestLink</td>
    </tr>
    <tr onmouseover="ChangeRowBg(this)" onmouseout="ChangeRowBg(this)" onmousedown="ChangeRowBg(this)" >
    <td>TestData</td>
    <td><a target=_blank href="new.htm">TestLink</td>
    </tr>
    <tr onmouseover="ChangeRowBg(this)" onmouseout="ChangeRowBg(this)" onmousedown="ChangeRowBg(this)" >
    <td>TestData</td>
    <td><a target=_blank href="new.htm">TestLink</td>
    </tr>
    <tr onmouseover="ChangeRowBg(this)" onmouseout="ChangeRowBg(this)" onmousedown="ChangeRowBg(this)" >
    <td>TestData</td>
    <td><a target=_blank href="new.htm">TestLink</td>
    </tr>
    </table>
    </body>
    </html>
    //--------在asp.net中的应用(对Datagrid利用如下函数进行初始化):--------

    public void ChangeRowBg(DataGrid grdTable)
      {   
         for(int i=0;i<grdTable.Items.Count;i++)
         {
           grdTable.Items[i].Attributes.Add("onmouseover","ChangeRowBg(this)");
           grdTable.Items[i].Attributes.Add("onmouseout","ChangeRowBg(this)");
           grdTable.Items[i].Attributes.Add("onmousedown","ChangeRowBg(this)");
         }   
      }

  • 相关阅读:
    可能不知道的C#特性
    设计模式の依赖注入
    How to find WWN and WWPN of HBA card in Linux
    fio IO测试工具
    centos/redhat 多路径存储使用 客户端
    centos/redhat 系统误删除逻辑卷之后如何恢复
    How to use lspci, lsscsi, lsusb, and lsblk to get Linux system devices information
    How to Check and Repair EXT4 Filesystem in Linux
    如何在 Linux 上扫描/检测新的 LUN 和 SCSI 磁盘
    小程序开发知识点总结归纳
  • 原文地址:https://www.cnblogs.com/SummerRain/p/214208.html
Copyright © 2020-2023  润新知