引用园区一朋友的点击某列排序,因项目需要自己改造成按多列排序 。
不多说,直接上,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;}
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