jQuery实现的表格前端排序功能示例

2020-05-23 06:18:09易采站长站整理

tbody.appendChild(trValue[arrtotal[k]]);
}
}
//tbody.appendChild(trValue[index]);
tbody.appendChild(fragment); //将排序的结果替换掉之前的值
tbody.sortCol = Idx;
}
}
});
})(jQuery);

2.页面函数


function desc_change(id,str){
$("#desc_1").html("日期");
$("#desc_2").html("ID");
$("#desc_3").html("类别");
$("#"+id).html(str);
}
function desc(id,str){
var htmlstr =$("#"+id).text().trim();
var c =str;
if(htmlstr==str){
c=str+'↓';
$("#"+id).html(c);
}else if(htmlstr==str+'↓'){
c=str+'↑'
$("#"+id).html(c);
}else if(htmlstr==str+'↑'){
c=str+'↓'
$("#"+id).html(c);
}
desc_change(id,c)
}

3.DOM结构


<table id="tableSort">
<thead>
<tr>
<th onclick="$.sortTable.sort('tableSort',0);desc('desc_1','日期')" ><a id="desc_1" >日期</a></th>
<th onclick="$.sortTable.sort('tableSort',1);desc('desc_2','软件ID')" ><a id="desc_2" >ID</a></th>
<th onclick="$.sortTable.sort('tableSort',2);desc('desc_x','渠道ID')" ><a id="desc_3" >类别</a></th>
</tr>
</thead>
<tbody>
<tr>
<td>201870601</td>
<td>汇总</td>
<td>新闻</td>
</tr>
</tbody>
</table>

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery表格(table)操作技巧汇总》、《jQuery切换特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery常见经典特效汇总》及《jquery选择器用法总结》

希望本文所述对大家jQuery程序设计有所帮助。