js 静态HTML表格排序功能实现
无标题文档
*{font-family:Arial, Helvetica, sans-serif;font-size:14px;border:none;}
body{text-align:center;}
table{margin:100px auto;}
td{width:100px;height:24px;text-align:center;line-height:24px;border:1px solid silver;}
.red{color:red;}
.top{background:#CCCCCC;cursor:pointer;}
.up{background:#FFFFCC url(/upload/20090211095733175.gif) no-repeat right 5px;}
.down{background:#FFFFCC url(/upload/20090211095734843.gif) no-repeat right 5px;}
.hov{background:#F0EFE5;}
kick me | kick me | kick me | kick me |
15.43 | 700 | 1.220 | 阿 |
7.05 | 4 | 3,000 | 炳 |
30.62 | 30 | 2,558,800 | 和 |
22.30 | 5 | 6 | 瞎 |
26.31 | 0.6 | 5 | - |
63.16 | 7 | 4 | 子 |
var tableSort = function(){
this.initialize.apply(this,arguments);
}
tableSort.prototype = {
initialize : function(tableId,clickRow,startRow,endRow,classUp,classDown,selectClass){
this.Table = document.getElementById(tableId);
this.rows = this.Table.rows;//所有行
this.Tags = this.rows[clickRow-1].cells;//标签td
this.up = classUp;
this.down = classDown;
this.startRow = startRow;
this.selectClass = selectClass;
this.endRow = (endRow == 999? this.rows.length : endRow);
this.T2Arr = this._td2Array();//所有受影响的td的二维数组
this.setShow();
},
//设置标签切换
setShow:function(){
var defaultClass = this.Tags[0].className;
for(var Tag ,i=0;Tag = this.Tags[i];i++){
Tag.index = i;
addEventListener(Tag ,'click', Bind(Tag,statu));
}
var _this =this;
var turn = 0;
function statu(){
for(var i=0;i]+>/g,"");
}
//------------------------------------------------
//tableid 第几行是标签行,从第几行开始排序,第几行结束排序(999表示最后) 升序标签样式,降序标签样式 选中列样式
//注意标签行的class应该是一致的
var ex1 = new tableSort('table',1,2,999,'up','down','hov');
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]