table美化-鼠标滑动单元格变色

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "<a href="http://www.w3.org/TR/html4/strict.dtd" target="_blank">http://www.w3.org/TR/html4/strict.dtd</a>">
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>orbitz-like behavior for hovering over table cells</title>
<style type="text/CSS">
.cssguycomments {background:#eee;border:#ddd;padding:8px;margin-bottom:40px;}
.cssguycomments p {font:normal 12px/18px verdana;}

table    {border-collapse:collapse;}
thead th {
    font:bold 13px/18px georgia;
    text-align:left;
    background:#fff4c6;
    color:#333;
    padding:8px 16px 8px 8px;
    border-right:1px solid #fff;
    border-bottom:1px solid #fff;
}

thead th.null {background:#fff;}
tbody th {
    font:bold 12px/15px georgia;
    text-align:left;
    background:#fff9e1;
    color:#333;
    padding:8px;
    border-bottom:1px solid #f3f0e4;
    border-right:1px solid #fff;
}
tbody td {
    font:normal 12px/15px georgia;
    color:#333;
    padding:8px;
    border-right:1px solid #f3f0e4;
    border-bottom:1px solid #f3f0e4;
}
/*  这3个是关键   –cssrain.cn */
tbody td.on {background:green;}  
thead th.on {background:red;}
tbody th.on {background:red;}
</style>

<script type="text/javascript">
/*
For functions getElementsByClassName, addClassName, and removeClassName
Copyright Robert Nyman, <a href="http://www.knowsky.com" target="_blank">http://www.knowsky.com</a>
Free to use if this text is included
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != ‘function’) {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function getElementsByClassName(className, tag, elm){
    var testClass = new RegExp("(^|s)" + className + "(s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for(var i=0; i<length; i++){
        current = elements[i];
        if(testClass.test(current.className)){
            returnElements.push(current);
        }
    }
    return returnElements;
}

function addClassName(elm, className){
    var currentClass = elm.className;
    if(!new RegExp(("(^|s)" + className + "(s|$)"), "i").test(currentClass)){
        elm.className = currentClass + ((currentClass.length > 0)? " " : "") + className;
    }
    return elm.className;
}

function removeClassName(elm, className){
    var classToRemove = new RegExp(("(^|s)" + className + "(s|$)"), "i");
    elm.className = elm.className.replace(classToRemove, "").replace(/^s+|s+$/g, "");
    return elm.className;
}

function makeTheTableHeadsHighlight() {
    // get all the td’s in the heart of the table…
    var table = document.getElementById(’rockartists’);
    var tbody = table.getElementsByTagName(’tbody’);
    var tbodytds = table.getElementsByTagName(’td’);
    // and loop through them…
    for (var i=0; i<tbodytds.length; i++) {
    // take note of their default class name
        tbodytds[i].oldClassName = tbodytds[i].className;
    // when someone moves their mouse over one of those cells…
        tbodytds[i].onmouSEOver = function() {
    // attach ‘on’ to the pointed cell
            addClassName(this,’on’);
    // attach ‘on’ to the th in the thead with the same class name
            var topheading = getElementsByClassName(this.oldClassName,’th’,table);
            addClassName(topheading[0],’on’);
    // attach ‘on’ to the far left th in the same row as this cell
            var row = this.parentNode;
            var rowheading = row.getElementsByTagName(’th’)[0];
            addClassName(rowheading,’on’);
        }
    // ok, now when someone moves their mouse away, undo everything we just did.
        tbodytds[i].onmouseout = function() {
    // remove ‘on’ from this cell
            removeClassName(this,’on’);
    // remove ‘on’ from the th in the thead
            var topheading = getElementsByClassName(this.oldClassName,’th’,table);
            removeClassName(topheading[0],’on’);

    // remove ‘on’ to the far left th in the same row as this cell
            var row = this.parentNode;
            var rowheading = row.getElementsByTagName(’th’)[0];
            removeClassName(rowheading,’on’);
        }
    }
}
addLoadEvent(makeTheTableHeadsHighlight);
</script>
</head>
<body>

<div class="cssguycomments">
<p>Final example with Javascript applied.  Hover over a table cell to see effects.  "View Source" and copy if you’d like to use.</p>
</div>

<table id="rockartists">
    <thead>
        <tr>
            <th class="null"> </th>
            <th class="stones">Rolling Stones</th>
            <th class="u2">U2</th>
            <th class="crue">Mötley Crüe</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th>Lead Vocals</th>
            <td class="stones">Mick Jagger</td>
            <td class="u2">Bono</td>
            <td class="crue">Vince Neil</td>
        </tr>
        <tr>
            <th>Lead Guitar</th>
            <td class="stones">Keith Richards</td>
            <td class="u2">The Edge</td>
            <td class="crue">Mick Mars</td>
        </tr>
        <tr>
            <th>Bass Guitar</th>
            <td class="stones">Ron Wood</td>
            <td class="u2">Adam Clayton</td>
            <td class="crue">Nikkie Sixx</td>
        </tr>
        <tr>
            <th>Drums</th>
            <td class="stones">Charlie Watts</td>
            <td class="u2">Larry Mullen, Jr.</td>
            <td class="crue">Tommy Lee</td>
        </tr>
    </tbody>
</table>

</body>

</html>

时间: 2025-01-19 01:10:49

table美化-鼠标滑动单元格变色的相关文章

javascript table美化鼠标滑动单元格变色_javascript技巧

Final example with JavaScript applied. Hover over a table cell to see effects. "View Source" and copy if you'd like to use. Rolling Stones U2 Mötley Crüe Lead Vocals Mick Jagger Bono Vince Neil Lead Guitar Keith Richards The Edge Mick Mars Bass

如何使指定ITEM单元格变色?(原创)

单元格|原创 如何使指定ITEM单元格变色? 问题描述: 如何在使用SETITEM后修改的各个单元格字体变成兰色,其他单元格仍保留黑色字体? 解决方案: string ls_modstring,ls_rows[] long ll_row,ll_col,ll_pos   for ll_pos = 1 to long(dw_1.object.datawindow.column.count)     ls_rows[ll_pos] = "" next   dw_1.setredraw(fal

EasyUI的doCellTip实现鼠标放到单元格上提示单元格内容_jquery

1:这个东西是我抄的(抄的哪儿的我就想不起来了- -)弹出的窗没有样式 不是很好看 //扩展 $.extend($.fn.datagrid.methods, { /** * 开打提示功能 * @param {} jq * @param {} params 提示消息框的样式 * @return {} */ doCellTip : function(jq, params) { function showTip(data, td, e) { if ($(td).text() == "") r

javascript 移动鼠标得到单元格所在table表中的rowIndex位置[兼容ie,firefox][原创]_javascript技巧

                 

鼠标移动到某个单元格上后,整个列都变色的实现方法_表单特效

                        [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 以上代码可以实现鼠标移动到单元格上,单元格变色,现在我想实现鼠标移动到某个单元格上后,整个列都变色不知道可以不可以实现呢? 如何定义表格的鼠标隔列变色行为 当鼠标经过时希望实现隔列变色(最好是反色) ,效果示例如下: [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 代码已经帖上来,现在鼠标移动到单元格变色 phx.rows[i].cells[j].onmouseover=fun

合并table相同单元格的jquery插件分享(很精简)_jquery

效果如下 原表格: col0 col1 col2 col3 SuZhou 11111 22222 SuZhouCity SuZhou 33333 44444 SuZhouCity SuZhou 55555 66666 SuZhouCity ShangHai 77777 88888 ShangHaiCity ShangHai uuuuu hhhhh ShangHaiCity ShangHai ggggg ccccc ShangHaiCity GuangZhou ttttt eeeee GuangZ

Jtable动态改变单元格 谢谢,急用!

问题描述 小弟现在在做排课算法,其中有一模块是录入老师不便排课的时间,在一个5*5的Jtable中通过点击相应的单元格来设置时间.5*5的Jtable刚开始全部为白色(表示都可用),当点击某一个单元格之后需要将其颜色设置为绿色(表示不可用),但当再次点击绿色的单元格时需将其再还原为白色(解决操作失误问题).自己的思路是用一个time[5][5]数组,全部初始化为1,当点击一次就将对应的值*(-1)来改变其值,然后遍历整个数组将值为-1对应的单元格置为蓝色.1,该事件应设置为mousePress(

Excel工作表选择单元格相关操作技巧

  1.启动Excel 2013并打开文档,在数据表中的任意一个单元格中单击选择该单元格后按"Ctrl+*"键,将能够选择当前所有的数据区域,如图1所示. 图1 选择当前数据区域 2.在工作表中单击一个单元格,如单元格A2,然后按住"Shift"键在另一个单元格中单击,如单元格E12,则将选择从单元格A2至E12之间的一个连续的单元格区域,如图2所示. 图2 选择连续单元格区域 注意 将鼠标指针放置到起始单元格上,按住左键移动鼠标到单元格区域右下角的单元格上释放鼠标

Excel怎么在一个单元格内输入多个值

  我们有时需要在某个单元格内连续输入多个数值,以查看引用此单元格的其他单元格的效果.但每次输入一个值后按回车键,活动单元格均默认下移一个单元格,非常不便.其实可以采用以下方法: 单击鼠标选定单元格,然后按住Ctrl键再次单击鼠标选定此单元格,此时,单元格周围将出现实线框,再输入数据,敲回车键就不会移动了.