RunSource

Using event delegation on an HTML table to highlight rows and columns.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

js代码:

require([
'dojo/on',
'dojo/dom-class',
'dojo/dom-attr',
'dojo/query', // note that dojo/query must be loaded for event delegation to work
'dojo/domReady!'
], function(on, domClass, domAttr, query) { var highlighter = { setCol: function(cellIdx, classStr, tbl) {
var i = 0, len = tbl.rows.length;
for (i; i < len; i++) {
var cell = tbl.rows[i].cells[cellIdx];
if (cell && !domAttr.has(cell, 'colspan')) { // provided index might not be available and skip header
//cells with colspan
domClass.toggle(cell, classStr)
}
}
}, highlightCol: function(cssQuery, classStr) {
var self = this;
query(cssQuery).on('td:mouseover, td:mouseout', function(evt) {
self.setCol(this.cellIndex, classStr, evt.currentTarget);
});
}, highlightRow: function(cssQuery, classStr) {
// note: this could also just be set through css with pseudoclass hover
query(cssQuery).on('tr:mouseover, tr:mouseout', function() {
domClass.toggle(this, classStr);
});
}, highlightBoth: function(cssQuery, classStrRow, classStrCol){
var self = this;
query(cssQuery).on('td:mouseover, td:mouseout', function(evt) {
var tbl = evt.currentTarget;
var tr = evt.target.parentNode;
var td = evt.target;
self.setCol(td.cellIndex, classStrCol, tbl);
domClass.toggle(tr, classStrRow);
});
}
}; highlighter.highlightBoth('#tbl', 'tdHover', 'trHover'); });
-----------------------------------------------------------------------------------------------------------------------------------------------
css代码:
#tbl { border-collapse: collapse; }
#tbl td, #tbl th { border-color: #AAAAAA; border-style: solid; border-width: 0 1px; padding: 3px 9px; } #tbl th { text-align: center; }
#tbl td, .tbl th { text-align: right; }
#tbl td:first-child { text-align: left; } .tdHover { background-color: #005197; color: #ffffff; }
.trHover { background-color: #E98900; color: #ffffff; }
-----------------------------------------------------------------------------------------------------------------------------------------------
html代码:
<table id="tbl">
<tbody>
<tr><th></th><th colspan="12">Main</th></tr>
<tr><th></th><th colspan="2">Sub 1</th><th colspan="2">Sub 2</th><th colspan="2">Sub 3</th>
<th colspan="2">Sub 4</th><th colspan="2">Sub 5</th><th colspan="2">Sub 6</th></tr>
<tr><th>Categories</th><th>Unit</th><th>± %</th><th>Unit</th><th>± %</th><th>Unit</th><th>± %</th><th>Unit</th>
<th>± %</th><th>Unit</th><th>± %</th><th>Unit</th><th>± %</th></tr>
<tr><td>Category 1</td><td>473</td><td>15</td><td>686</td><td>540</td><td>141</td><td>101</td><td>1935</td>
<td>745</td><td>43</td><td>161</td><td>515</td><td>52</td></tr>
<tr><td>Category 2</td><td>20</td><td>161</td><td>127</td><td>13</td><td>201</td><td>14</td><td>278</td>
<td>31</td><td>921</td><td>519</td><td>103</td><td>608</td></tr>
<tr><td>Category 3</td><td>18</td><td>80</td><td>10</td><td>99</td><td>5</td><td>71</td><td>3</td>
<td>70</td><td>1</td><td>105</td><td>10</td><td>45</td></tr>
<tr><td>Catogory 4</td><td>378</td><td>9</td><td>943</td><td>11</td><td>1747</td><td>94</td>
<td>236</td><td>19</td><td>3265</td><td>95</td><td>6788</td><td>4</td></tr>
</tbody>
</table>
-----------------------------------------------------------------------------------------------------------------------------
代码运行效果:


dojo小代码的更多相关文章

  1. 【processing】小代码

    今天无意间发现的processing 很有兴趣 实现很简洁 void setup(){ } void draw(){ background(); && mouseY > heig ...

  2. 小代码编写神器:LINQPad 使用入门

    原文:小代码编写神器:LINQPad 使用入门 一:概述 1:想查看程序运行结果,又不想启动 VS 怎么办? 2:想测试下自己的 C# 能力,不使用 VS 的智能感知,怎么办? 那么,我们有一个选择, ...

  3. Python小代码_2_格式化输出

    Python小代码_2_格式化输出 name = input("name:") age = input("age:") job = input("jo ...

  4. Python小代码_1_九九乘法表

    Python小代码_1_九九乘法表 max_num = 9 row = 1 while row <= max_num: col = 1 while col <= row: print(st ...

  5. 简单的Java逻辑小代码(打擂台,冒泡排序,水仙花数,回文数,递归)

    1.打擂台 简单的小代码,打擂台.纪念下过去,祝福下新人. public static void main(String[] args){ int[] ld = {1,4,2,10,8,9,5}; i ...

  6. python的mysql小代码

    我因为懒,就想写个批量insert数据的小代码 这里是代码 # _*_ encoding:utf-8 _*_ import os import MySQLdb import numpy as np d ...

  7. 一段小代码秒懂C++右值引用和RVO(返回值优化)的误区

    关于C++右值引用的参考文档里面有明确提到,右值引用可以延长临时变量的周期.如: std::string&& r3 = s1 + s1; // okay: rvalue referen ...

  8. 【processing】小代码4

    translate(x,y);  移动坐标原点到x,y处 rotate(angle); 坐标沿原点顺时针转动angle度 scale(n); 绘制图像放大n倍 pushMatrix() 将当前坐标压入 ...

  9. Android版微信小代码(转)

    以下代码仅适用于Android版微信: //switchtabpos:让微信tab更贴合Android Design 如果你并不喜欢微信Android版和iOS端同用一套UI,现在有一个小方法可以实现 ...

随机推荐

  1. 20135327郭皓--Linux内核分析第八周 进程的切换和系统的一般执行过程

    第八周 进程的切换和系统的一般执行过程 一.进程切换的关键代码switch_to分析 1.进程调度与进程调度的时机分析 不同类型的进程有不同的调度需求 第一种分类: I/O-bound:频繁进行I/O ...

  2. MYSQL jdbc autoReconnect

    http://blog.csdn.net/a9529lty/article/details/7104351 http://blog.163.com/huangfei_person/blog/stati ...

  3. Node 表单query

    //#使用nodejs编写动态的web服务器//1:加载需要模块 fs http urlconst fs = require("fs");const http = require( ...

  4. SAP顾问岗位要求

    岗位职责: 1.负责SAP系统各模块日常运维工作,解决用户在系统操作过程中遇到的问题: 2.评估用户需求(新需求.功能优化)的可实现性,完成SAP系统及相关系统的配置调整及功能实现: 3.负责CRM等 ...

  5. HADOOP实战

    一.软件版本Centos6.5.VMware 10CDH5.2.0(Hadoop 2.5.0)Hive-0.13 sqoop-1.4.5 二.学完课程之后,您可以:①.一个人搞定企业Hadoop平台搭 ...

  6. 《使用python进行数据分析》

    第一 环境搭建 1. 使用pip安装pandas, numpy, scipy, matplotlib, ipython 注意:首先需要安装venv(不然在下面的安装过程中会提示很多的错误,使用pych ...

  7. delphi dbgrid 修改、更新、删除

    https://zhidao.baidu.com/question/580946797.html DELPHI 中,使用 dbgrid显示数据.窗体上放置三个按钮,caption分别为:修改.删除.更 ...

  8. AtCoder WTF 2019 C2. Triangular Lamps Hard

    题目链接 感觉这样的题真的称得上是鬼斧神工啊,\(\text{OI}\)中能多一些这样的题目就太好了. 题意: 有一个二维的三角坐标系,大概如图所示(图是从atcoder里偷下来的): 坐标系上的每个 ...

  9. Django-website 程序案例系列-9 分页

    分页例子程序: LIST = [] #全局列表 for i in range(103): #1:100的列表 LIST.append(i) def user_list(request): curren ...

  10. BZOJ3417[Poi2013]Tales of seafaring——BFS

    题目描述 Young Bytensson loves to hang out in the port tavern, where he often listens to the sea dogs te ...