JavaScript 表格高亮类的应用[高级]
2009-11-04 00:00
351 查看
表格高亮
* {
font-size: 11px;
font-family: verdana, arial, sans-serif;
}
table {
border: 1px solid #ccc;
margin: 0 auto;
}
th {
background-color: #f7f7f7;
}
td, th {
padding: 15px;
border: 1px solid #ccc;
}
tr.alternate {
background-color: #efd;
}
.bold {
font-weight: bold;
}
.red {
color: red;
font-weight: bold;
}
.blue {
background-color: blue;
}
/* Used with crosshairs.js */
.hoverHilight {
background-color: #ffffc0;
cursor: pointer;
}
.activeCellHilight {
background-color: #c0dbff;
color: blue;
}
var hilightClass = "hoverHilight";
var activeHilightClass = "activeCellHilight";
var hilightActive = 1;
var hilightCol = 1;
var hilightRow = 1;
var hilightTopHeader = 0;
var hilightLeftHeader = 0;
var hilightRightHeader = 0;
var hilightBottomHeader = 0;
var surroundActive = 0;
function initCrossHairsTable(id, topPad, rightPad, bottomPad, leftPad) {
var tableObj = document.getElementById(id);
var c = tableObj.rows[0].cells.length - rightPad;
var r = tableObj.rows.length - bottomPad;
for (var i = topPad; i < r; i++)
{
for (var j = leftPad; j < c; j++)
{
if(!document.all) {
tableObj.rows[i].cells[j].setAttribute("onmouseover","addHilight(this);");
tableObj.rows[i].cells[j].setAttribute("onmouseout","removeHilight(this);");
}
else
{
tableObj.rows[i].cells[j].onmouseover = function() { addHilight(this); }
tableObj.rows[i].cells[j].onmouseout = function() { removeHilight(this); }
}
}
}
}
function addHilight(cell)
{
applyHilight(cell.parentNode.parentNode.parentNode,
cell.parentNode.rowIndex, cell.cellIndex, 1);
}
function removeHilight(cell)
{
applyHilight(cell.parentNode.parentNode.parentNode,
cell.parentNode.rowIndex, cell.cellIndex, 0);
}
var oldRowClasses = "";
var oldHeaderClasses = "";
var oldCellClasses = new Array();
function applyHilight(obj, rowIndex, colIndex, state)
{
var W3CDOM = (document.createElement && document.getElementsByTagName);
if (!W3CDOM)
{
alert("This script requires W3C DOM support")
return;
}
if (hilightClass == "") alert("Please set a hilight class.");
if (hilightRow) applyHilightRow(obj, rowIndex, colIndex, state);
if (hilightCol) applyHilightCol(obj, rowIndex, colIndex, state);
if (hilightTopHeader) applyHilightTopHeader(obj, rowIndex, colIndex, state);
if (hilightLeftHeader) applyHilightLeftHeader(obj, rowIndex, colIndex, state);
if (hilightRightHeader) applyHilightRightHeader(obj, rowIndex, colIndex, state);
if (hilightBottomHeader) applyHilightBottomFooter(obj, rowIndex, colIndex, state);
if (hilightActive) applyHilightActiveCell(obj, rowIndex, colIndex, state);
if (surroundActive) applySurroundActiveHilight(obj, rowIndex, colIndex, state);
}
function applyHilightLeftHeader(obj, rowIndex, colIndex, state)
{
var classArray;
var rowClasses = "";
if (state == 1)
{
obj.rows[rowIndex].cells[0].className += " " + hilightClass;
}
else
{
classArray = obj.rows[rowIndex].cells[0].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") rowClasses += " " + classArray[i];
obj.rows[rowIndex].cells[0].className = rowClasses;
}
}
function applyHilightRightHeader(obj, rowIndex, colIndex, state)
{
var classArray;
var rowClasses = "";
if (state == 1)
{
obj.rows[rowIndex].cells[obj.rows[rowIndex].cells.length-1].className += " " + hilightClass;
}
else
{
classArray = obj.rows[rowIndex].cells[obj.rows[rowIndex].cells.length-1].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") rowClasses += " " + classArray[i];
obj.rows[rowIndex].cells[obj.rows[rowIndex].cells.length-1].className = rowClasses;
}
}
function applyHilightTopHeader(obj, rowIndex, colIndex, state)
{
var classArray;
var colClasses = "";
if (state == 1)
{
obj.rows[0].cells[colIndex].className += " " + hilightClass;
}
else
{
classArray = obj.rows[0].cells[colIndex].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") colClasses += " " + classArray[i];
obj.rows[0].cells[colIndex].className = colClasses;
}
}
function applyHilightBottomFooter(obj, rowIndex, colIndex, state)
{
var classArray;
var colClasses = "";
if (state == 1)
{
obj.rows[obj.rows.length-1].cells[colIndex].className += " " + hilightClass;
}
else
{
classArray = obj.rows[obj.rows.length-1].cells[colIndex].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") colClasses += " " + classArray[i];
obj.rows[obj.rows.length-1].cells[colIndex].className = colClasses;
}
}
function applyHilightRow(obj, rowIndex, colIndex, state)
{
if (state == 1)
{
oldRowClasses = obj.rows[rowIndex].className;
obj.rows[rowIndex].className = hilightClass;
}
else
{
obj.rows[rowIndex].className = oldRowClasses;
}
}
function applyHilightCol(obj, rowIndex, colIndex, state)
{
var cellClasses = new Array();
if (state == 1)
{
for(var i = 0; i < obj.rows.length; i++)
{
cellClasses.push(obj.rows[i].cells[colIndex].className);
obj.rows[i].cells[colIndex].className += " " + hilightClass;
}
oldCellClasses = cellClasses;
}
else
{
oldCellClasses.reverse();
for(var i = 0; i < obj.rows.length; i++)
obj.rows[i].cells[colIndex].className = oldCellClasses.pop();
}
}
var oldActiveCellClasses;
function applyHilightActiveCell(obj, rowIndex, colIndex, state)
{
if (state == 1)
{
oldActiveCellClasses = null;
oldActiveCellClasses = obj.rows[rowIndex].cells[colIndex].className;
obj.rows[rowIndex].cells[colIndex].className += " " + activeHilightClass;
}
else
{
var oldClasses = oldActiveCellClasses.split(" ");
obj.rows[rowIndex].cells[colIndex].className = "";
for(var i = 0; i < oldClasses.length; i++)
{
if(oldClasses[i] != hilightClass) obj.rows[rowIndex].cells[colIndex].className += " " + oldClasses[i];
oldActiveCellClasses = "";
}
}
}
function applySurroundActiveHilight(obj, rowIndex, colIndex, state)
{
var surroundRadius = 1;
var radiusColor = "#c0dbff"
var cell;
if(!parseInt(surroundRadius)) return;
if (state == 1)
{
for(var i = (rowIndex - surroundRadius); i
* {
font-size: 11px;
font-family: verdana, arial, sans-serif;
}
table {
border: 1px solid #ccc;
margin: 0 auto;
}
th {
background-color: #f7f7f7;
}
td, th {
padding: 15px;
border: 1px solid #ccc;
}
tr.alternate {
background-color: #efd;
}
.bold {
font-weight: bold;
}
.red {
color: red;
font-weight: bold;
}
.blue {
background-color: blue;
}
/* Used with crosshairs.js */
.hoverHilight {
background-color: #ffffc0;
cursor: pointer;
}
.activeCellHilight {
background-color: #c0dbff;
color: blue;
}
var hilightClass = "hoverHilight";
var activeHilightClass = "activeCellHilight";
var hilightActive = 1;
var hilightCol = 1;
var hilightRow = 1;
var hilightTopHeader = 0;
var hilightLeftHeader = 0;
var hilightRightHeader = 0;
var hilightBottomHeader = 0;
var surroundActive = 0;
function initCrossHairsTable(id, topPad, rightPad, bottomPad, leftPad) {
var tableObj = document.getElementById(id);
var c = tableObj.rows[0].cells.length - rightPad;
var r = tableObj.rows.length - bottomPad;
for (var i = topPad; i < r; i++)
{
for (var j = leftPad; j < c; j++)
{
if(!document.all) {
tableObj.rows[i].cells[j].setAttribute("onmouseover","addHilight(this);");
tableObj.rows[i].cells[j].setAttribute("onmouseout","removeHilight(this);");
}
else
{
tableObj.rows[i].cells[j].onmouseover = function() { addHilight(this); }
tableObj.rows[i].cells[j].onmouseout = function() { removeHilight(this); }
}
}
}
}
function addHilight(cell)
{
applyHilight(cell.parentNode.parentNode.parentNode,
cell.parentNode.rowIndex, cell.cellIndex, 1);
}
function removeHilight(cell)
{
applyHilight(cell.parentNode.parentNode.parentNode,
cell.parentNode.rowIndex, cell.cellIndex, 0);
}
var oldRowClasses = "";
var oldHeaderClasses = "";
var oldCellClasses = new Array();
function applyHilight(obj, rowIndex, colIndex, state)
{
var W3CDOM = (document.createElement && document.getElementsByTagName);
if (!W3CDOM)
{
alert("This script requires W3C DOM support")
return;
}
if (hilightClass == "") alert("Please set a hilight class.");
if (hilightRow) applyHilightRow(obj, rowIndex, colIndex, state);
if (hilightCol) applyHilightCol(obj, rowIndex, colIndex, state);
if (hilightTopHeader) applyHilightTopHeader(obj, rowIndex, colIndex, state);
if (hilightLeftHeader) applyHilightLeftHeader(obj, rowIndex, colIndex, state);
if (hilightRightHeader) applyHilightRightHeader(obj, rowIndex, colIndex, state);
if (hilightBottomHeader) applyHilightBottomFooter(obj, rowIndex, colIndex, state);
if (hilightActive) applyHilightActiveCell(obj, rowIndex, colIndex, state);
if (surroundActive) applySurroundActiveHilight(obj, rowIndex, colIndex, state);
}
function applyHilightLeftHeader(obj, rowIndex, colIndex, state)
{
var classArray;
var rowClasses = "";
if (state == 1)
{
obj.rows[rowIndex].cells[0].className += " " + hilightClass;
}
else
{
classArray = obj.rows[rowIndex].cells[0].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") rowClasses += " " + classArray[i];
obj.rows[rowIndex].cells[0].className = rowClasses;
}
}
function applyHilightRightHeader(obj, rowIndex, colIndex, state)
{
var classArray;
var rowClasses = "";
if (state == 1)
{
obj.rows[rowIndex].cells[obj.rows[rowIndex].cells.length-1].className += " " + hilightClass;
}
else
{
classArray = obj.rows[rowIndex].cells[obj.rows[rowIndex].cells.length-1].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") rowClasses += " " + classArray[i];
obj.rows[rowIndex].cells[obj.rows[rowIndex].cells.length-1].className = rowClasses;
}
}
function applyHilightTopHeader(obj, rowIndex, colIndex, state)
{
var classArray;
var colClasses = "";
if (state == 1)
{
obj.rows[0].cells[colIndex].className += " " + hilightClass;
}
else
{
classArray = obj.rows[0].cells[colIndex].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") colClasses += " " + classArray[i];
obj.rows[0].cells[colIndex].className = colClasses;
}
}
function applyHilightBottomFooter(obj, rowIndex, colIndex, state)
{
var classArray;
var colClasses = "";
if (state == 1)
{
obj.rows[obj.rows.length-1].cells[colIndex].className += " " + hilightClass;
}
else
{
classArray = obj.rows[obj.rows.length-1].cells[colIndex].className.split(" ");
for(var i = 0; i < (classArray.length - 1); i++)
if(classArray[i] != "") colClasses += " " + classArray[i];
obj.rows[obj.rows.length-1].cells[colIndex].className = colClasses;
}
}
function applyHilightRow(obj, rowIndex, colIndex, state)
{
if (state == 1)
{
oldRowClasses = obj.rows[rowIndex].className;
obj.rows[rowIndex].className = hilightClass;
}
else
{
obj.rows[rowIndex].className = oldRowClasses;
}
}
function applyHilightCol(obj, rowIndex, colIndex, state)
{
var cellClasses = new Array();
if (state == 1)
{
for(var i = 0; i < obj.rows.length; i++)
{
cellClasses.push(obj.rows[i].cells[colIndex].className);
obj.rows[i].cells[colIndex].className += " " + hilightClass;
}
oldCellClasses = cellClasses;
}
else
{
oldCellClasses.reverse();
for(var i = 0; i < obj.rows.length; i++)
obj.rows[i].cells[colIndex].className = oldCellClasses.pop();
}
}
var oldActiveCellClasses;
function applyHilightActiveCell(obj, rowIndex, colIndex, state)
{
if (state == 1)
{
oldActiveCellClasses = null;
oldActiveCellClasses = obj.rows[rowIndex].cells[colIndex].className;
obj.rows[rowIndex].cells[colIndex].className += " " + activeHilightClass;
}
else
{
var oldClasses = oldActiveCellClasses.split(" ");
obj.rows[rowIndex].cells[colIndex].className = "";
for(var i = 0; i < oldClasses.length; i++)
{
if(oldClasses[i] != hilightClass) obj.rows[rowIndex].cells[colIndex].className += " " + oldClasses[i];
oldActiveCellClasses = "";
}
}
}
function applySurroundActiveHilight(obj, rowIndex, colIndex, state)
{
var surroundRadius = 1;
var radiusColor = "#c0dbff"
var cell;
if(!parseInt(surroundRadius)) return;
if (state == 1)
{
for(var i = (rowIndex - surroundRadius); i
相关文章推荐
- JavaScript 表格高亮类的应用[高级]
- JavaScript 学习笔记十一 函数高级应用
- 25、DOM的高级应用2-------表格内容的排序
- DOM高级应用——表格元素的添加、删除、搜索操作1
- JavaScript高级程序设计 阅读笔记(十九) js表格排序
- JavaScript高级应用:使用DOM技术操纵文档
- JavaScript事件高级应用
- JavaScript 学习笔记十一 函数高级应用
- JavaScript高级应用:使用DOM技术操纵文档
- 【javascript】表格行间隔显示颜色,并实现高亮显示效果
- javaScript高级应用(二)
- javascript表格行高亮显示
- JavaScript高级应用:例外处理
- Javascript高级应用:文件操作篇
- JavaScript高级应用——类与函数篇
- javaScript高级应用 一
- javascript应用 往表格中出入行,每次都插入第一行。
- javascript的高级应用
- 使用 Dojo 的 Ajax 应用开发进阶教程,第 1 部分: JavaScript 技巧与高级特性
- javascript高级应用