IT技术库 - 技术成就梦想
首页
网络编程
发布时间:2023-07-24 15:33:03
js table排序类代码
table
js
排序
table排序类
名称
/
类型
上传时间
大小
new.rar
2008-9-12 8:51:09
423.09 K
TagControl.js
2008-9-23 11:26:57
1.35 K
Scroller.js
2008-9-23 11:26:57
2.5 K
AlertBox.js
2008-9-23 11:26:57
3.48 K
1.htm
2008-10-4 20:21:54
11.13 K
4.htm
2008-10-4 20:21:54
351 b
news.xml
2008-10-4 20:24:11
13.74 K
news.xsl
2008-10-4 20:24:11
16.4 K
function.js
2008-10-4 20:24:11
2.78 K
<script type="text/javascript"> var $ = function (id) { return "string" == typeof id ? document.getElementById(id) : id; }; var Class = { create: function() { return function() { this.initialize.apply(this, arguments); } } } Object.extend = function(destination, source) { for (var property in source) { destination[property] = source[property]; } return destination; } function Each(list, fun){ for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); } }; ///////////////////////////////////// //////////////////////////////// var TableOrder = Class.create(); TableOrder.prototype = { initialize: function(tbody) { var oThis = this; this.Body = $(tbody);//tbody对象 this.Rows = [];//行集合 Each(this.Body.rows, function(o){ oThis.Rows.push(o); }) }, //排序并显示 Sort: function(order) { //排序 this.Rows.sort(this.Compare(order)); order.Down && this.Rows.reverse(); //显示表格 var oFragment = document.createDocumentFragment(); Each(this.Rows, function(o){ oFragment.appendChild(o); }); this.Body.appendChild(oFragment); }, //比较函数 Compare: function(order) { var oThis = this; return function(o1, o2) { var value1 = oThis.GetValue(o1, order), value2 = oThis.GetValue(o2, order); return value1 < value2 ? -1 : value1 > value2 ? 1 : 0; }; }, //获取比较值 GetValue: function(tr, order) { var data = tr.getElementsByTagName("td")[order.Index].getAttribute(order.Attribute); //数据转换 switch (order.DataType.toLowerCase()) { case "int": return parseInt(data) || 0; case "float": return parseFloat(data) || 0; case "date": return Date.parse(data) || 0; case "string": default: return data.toString() || ""; } }, //添加并返回一个排序对象 Add: function(index, options) { var oThis = this; return new function(){ //默认属性 this.Attribute = "innerHTML";//获取数据的属性 this.DataType = "string";//数据类型 this.Down = false;//是否按顺序 Object.extend(this, options || {}); //排序对象的属性 this.Index = index; this.Sort = function(){ oThis.Sort(this); }; }; } } var to = new TableOrder("idList"); function SetOrder(obj, index, options){ var o = $(obj); //添加一个排序对象 var order = to.Add(index, options); o.onclick = function(){ //取相反排序 order.Down = !order.Down; //设置样式 Each(SetOrder._arr, function(o){ o.className = ""; }) o.className = order.Down ? "down" : "up"; //排序显示 order.Sort(); return false; } //_arr是记录排序项目(这里主要用来设置样式) SetOrder._arr ? SetOrder._arr.push(o) : SetOrder._arr = []; } SetOrder("idTitle", 0); SetOrder("idExt", 0, { Attribute: "_ext" }); SetOrder("idAddtime", 1, { Attribute: "_order", DataType: "date" }); SetOrder("idSize", 2, { Attribute: "_order", DataType: "int" }); </script>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
你可能感兴趣的
一段利用WSH获取登录时间的jscript代码
23-07-24
jscript
wsh
html 锁定页面(js遮罩层弹出div效果)
23-07-24
js
遮罩层
$.ajax json数据传递方法
23-07-24
ajax
json
用js重建星际争霸
23-07-24
js
星际争霸
js重建
星际争霸2
不间断滚动JS打包类,基本可以实现所有的滚动效果,太强了
23-07-24
js
打包
一些不错的JS 自定义函数第1/2页
23-07-24
自定义函数
js
js跨域和ajax 跨域问题的实现思路
23-07-24
ajax
跨域
js
跨域问题
JQery 渐变图片导航效果代码 漂亮
23-07-24
js
jquery
代码
js table排序类代码
23-07-24
table
js
排序
大家未必知道的Js技巧收藏
23-07-24
js
js技巧