javascrpt超强html表格(table)指定多列排序

本文介绍了一种利用jQuery插件TableSorter实现表格多列排序的方法。通过修改本地jQuery目录下的代码,可以轻松实现表格中多列的升序和降序排序功能,并附带了详细的使用说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

引用园区一朋友的点击某列排序,因项目需要自己改造成按多列排序 。
不多说,直接上,jquery.js本地要有的吧。直接修改本地jquey目录,复制以下代码即可。


TableSorter

body{font-size:12px;line-height:25px;}
tr{height:25px;}
th{font-size:14px;border-bottom:solid 1px #DDDDDD;background-color:#EEEEEE;}
td{font-size:12px;text-align:center;}
.SortDescCss{background-image:url(http://k2046.cn/tb/Desc.gif);background-repeat:no-repeat;background-position:right center;}
.SortAscCss{background-image:url(http://k2046.cn/tb/Asc.gif);background-repeat:no-repeat;background-position:right center;}

(function ( ) {
        var oldHTML =
) {        var oldHTML =
.fn.html; .fn.formhtml = function () {
            if (arguments.length) return oldHTML.apply(this, arguments);
.fn.formhtml = function () {            if (arguments.length) return oldHTML.apply(this, arguments);
("input,textarea,button", this).each(function () { this.setAttribute('value', this.value); }); (":radio,:checkbox",this).each(function()if(this.checked)this.setAttribute(checked,checked);elsethis.removeAttribute(checked);); ( ": r a d i o , : c h e c k b o x " , t h i s ) . e a c h ( f u n c t i o n ( ) i f ( t h i s . c h e c k e d ) t h i s . s e t A t t r i b u t e ( ′ c h e c k e d ′ , ′ c h e c k e d ′ ) ; e l s e t h i s . r e m o v e A t t r i b u t e ( ′ c h e c k e d ′ ) ; ) ; ("option", this).each(function () { if (this.selected) this.setAttribute('selected', 'selected'); else this.removeAttribute('selected'); }); return oldHTML.apply(this); }; })(jQuery); /*使用说明 : 方法1: var tbl = new TableSorter("tb1"); //参数name为table列的序号,type为数据格式(1:字符,2:数字) var p = [{ "name": 4, "type": 1 }, { "name": 5, "type": 2}]; tbl.Sort( p ) ; */ function TableSorter(table) { this.Table = this.dom(table); if (this.Table.rows.length
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值