html段落自动排序,HTML表格自动排序

jquery-tablesort

5ba32ea46b46fd13d6aa2c8ad84ab1a8.gif

table sort

* {

margin: 0;

padding: 0;

}

body {

font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

color: #4f6b72;

background: #E6EAE9;

}

#container {

display: flex;

align-items: center;

justify-content: center;

width: 100vw;

margin: 0 auto;

}

table {

width: 90%;

max-width: 500px;

font-size: 18px;

text-align: center;

margin-top: 50px;

}

th {

color: white;

font-size: 20px;

border-right: 1px solid #C1DAD7;

border-bottom: 1px solid #C1DAD7;

border-top: 1px solid #C1DAD7;

text-transform: uppercase;

background:#b6b6f0;;

}

tr{

height: 45px;

}

tr:nth-child(odd){

background: #e6e6fa;

}

tr:nth-child(even){

background:#fff0f5;

}

td {

border-right: 1px solid #C1DAD7;

border-bottom: 1px solid #C1DAD7;

color: #4f6b72;

}

ID姓名年龄手机号

1Colin83180714959842Van83134931011853Bryson86139680225554Buzz35133969555435Eve41131629165706May49138276273037Andrew1189724479158Barry81138211800769Zona941820378529910Buddy361382018854911Eve321313652274712Buddy191898883720913Kevin241336979779614Zora581327520771615Hailey161597434989716Bahar951528858646717Bahar601306829633618Joyce711596963042419Angelia161827955486020Lance2715842451834

$(function () {

$("#mytable").tablesort();

$('thead th.number').data('sortBy', function(th, td, sorter) {

return parseInt(td.text(), 10);

});

});

tablesort默认是使用字符串排序,可以通过将某列转换为具体的类型来实现自定义排序。

例如,上面例子中将指定的列转换为int类型再进行排序。

注意:必须包含THEAD和TBODY,否则表头也会参与排序。

tablesorter

table sort

* {

margin: 0;

padding: 0;

}

body {

font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

color: #4f6b72;

background: #E6EAE9;

}

#container {

display: flex;

align-items: center;

justify-content: center;

width: 100vw;

margin: 0 auto;

}

table {

width: 90%;

max-width: 500px;

font-size: 18px;

text-align: center;

margin-top: 50px;

}

th {

color: white;

font-size: 20px;

border-right: 1px solid #C1DAD7;

border-bottom: 1px solid #C1DAD7;

border-top: 1px solid #C1DAD7;

text-transform: uppercase;

background: #b6b6f0;

;

}

tr {

height: 45px;

}

tr:nth-child(odd) {

background: #e6e6fa;

}

tr:nth-child(even) {

background: #fff0f5;

}

td {

border-right: 1px solid #C1DAD7;

border-bottom: 1px solid #C1DAD7;

color: #4f6b72;

}

ID姓名年龄手机号

1Colin83180714959842Van83134931011853Bryson86139680225554Buzz35133969555435Eve41131629165706May49138276273037Andrew1189724479158Barry81138211800769Zona941820378529910Buddy361382018854911Eve321313652274712Buddy191898883720913Kevin241336979779614Zora581327520771615Hailey161597434989716Bahar951528858646717Bahar601306829633618Joyce711596963042419Angelia161827955486020Lance2715842451834

$(function () {

$("#mytable").tablesorter();

});

tablesorter可以看作是jquery-tablesort的升级版,最重要的就是可以自动探测数据类型。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值