您正在使用 IPV4 [18.117.107.90] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
悟空收录网       [公益]保护绿色环境,构建和谐社会      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 劳动节 012
2024年 端午节 052
2025年 元 旦 257
2025年 春 节 285
 
您现在的位置:首页 >> 脚本代码 >> 内容
本类新增
本类热门
JS实现简单表格排序操作示例
内容摘要: !DOCTYPEhtmlheadmetahttp-equiv='Content-type'content='text/html'charset='utf-8'titlesorttable/titlestyle*{margin:0px;padding:0px;}body{background:#ccc;}table{width:350px;margin:0au......
<!DOCTYPE>

<html>

<head>

<metahttp-equiv="Content-type"content="text/html"charset="utf-8">

<title>sorttable</title>

<style>

*{

margin:0px;

padding:0px;

}

body{

background:#ccc;

}

table{

width:350px;

margin:0auto;

background-color:#eee;

}

tableth{

cursor:hand;

padding:5px0;

background-color:#999;

}

tabletd{

background-color:#fff;

font-size:16px;

font-weight:normal;

text-align:center;

line-height:30px;

}

</style>

<scriptlanguage="javascript">

functionsortCells(type){

vartbs=document.getElementsByTagName("table")[0];

vararr=[];

vararr2=[];

for(vari=1;i<tbs.rows.length;i++){

vartext=tbs.rows[i].cells[type].innerText;

arr.push(text);

arr2[text]=i;

}

if(type==0){

arr.sort(function(a,b){returna-b});

}else{

arr.sort();

}

vartemp="";

for(varj=1;j<tbs.rows.length;j++){

temp=tbs.rows[j].cells[0].innerText;

tbs.rows[j].cells[0].innerText=tbs.rows[arr2[arr[j-1]]].cells[0].innerText;

tbs.rows[arr2[arr[j-1]]].cells[0].innerText=temp;

temp=tbs.rows[j].cells[1].innerText;

tbs.rows[j].cells[1].innerText=tbs.rows[arr2[arr[j-1]]].cells[1].innerText;

tbs.rows[arr2[arr[j-1]]].cells[1].innerText=temp;

temp=tbs.rows[j].cells[2].innerText;

tbs.rows[j].cells[2].innerText=tbs.rows[arr2[arr[j-1]]].cells[2].innerText;

tbs.rows[arr2[arr[j-1]]].cells[2].innerText=temp;

//console.log(arr2);

for(vari=1;i<tbs.rows.length;i++){

vartext=tbs.rows[i].cells[type].innerText;

arr2[text]=i;

}

}

}

</script>

</head>

<body>

<center>sorttable</center>

<tableborder="0">

<tr>

<thonclick="sortCells(0);">序号</th>

<thonclick="sortCells(1);">姓名</th>

<thonclick="sortCells(2);">日期</th>

</tr>

<tr>

<td>2</td>

<td>BB</td>

<td>2015-09-12</td>

</tr>

<tr>

<td>3</td>

<td>CC</td>

<td>2015-07-12</td>

</tr>

<tr>

<td>1</td>

<td>AA</td>

<td>2015-09-11</td>

</tr>

<tr>

<td>4</td>

<td>DD</td>

<td>2015-06-12</td>

</tr>

</table>

</body>

</html>

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:css旋转导航的示例代码

 

下一篇:使用CSS实现音波加载效果

发布日期:2023/4/27
手机扫二维码直达本页
发布时间:13:16:11
点  击:3
录  入:齐天大圣
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....