HTML输入学生成绩并排序java_[Java教程]利用js排序html表格

js排序特效

.main{ height:auto; overflow:hidden; margin:0px auto;}

.main td{ text-align:center; height:28px; width:100px; line-height:28px ; font-size:14px; color:#555;}

.main .title td{ cursor:pointer; color:#333}

.none{ display:none}

$(function(){

var pk=1;

$(".title td").click(function(){

// 把要排序的内容添加到数组里

var tIndex=parseInt($(this).index());

var valueArray=new Array();

var p=0;

for(var i=1; i

if(tIndex!=0){

valueArray[p]=parseInt($("table tr:eq("+i+") td").eq(tIndex).html());

}else{

valueArray[p]=$("table tr:eq("+i+") td").eq(tIndex).html();

}

p++;

}

//数据排序

if(pk==1){

valueArray.sort(function(a,b){ return a

pk=2

}else{

valueArray.sort(function(a,b){ return a>b ? -1:1})

pk=1

}

//匹配内容 加入到一个隐藏的排序div里+-

for(var i=0; i

for(var d=1; d

var valueText= tIndex!=0 ? parseInt($("table tr:eq("+d+") td").eq(tIndex).html()):$("table tr:eq("+d+") td").eq(tIndex).html();

if(valueArray[i]==valueText){

$("table tr").eq(d).clone().appendTo(".none")

}

}

}

//重新整理html 排序,添加到视图里

var titleClone=$("table tr").eq(0).clone(true);

$("table").html("").append(titleClone);

$("table").append($(".none").html())

$(".none").html("");

})

})

姓名年龄出生年分数
李百(L)15198899
王易(W)252000150
林明(L)181745120
李姐(L)201996130
特效出自:kevn- web前段开发
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值