具备排序功能的表格(JS+CSS+table)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//-----------------------------------------------------------------------------
// sortTable(id, col, rev)
//
// id - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted.
// col - Index of the column to sort, 0 = first column, 1 = second column,
// etc.
// rev - If true, the column is sorted in reverse (descending) order
// initially.
//
// Note: the team name column (index 1) is used as a secondary sort column and // always sorted in ascending order.
//-----------------------------------------------------------------------------
function sortTable(id, col, rev) {
// Get the table or table section to sort.
var tblEl = document.getElementById(id);
// The first time this function is called for a given table, set up an
// array of reverse sort flags.
if (tblEl.reverseSort == null) {
tblEl.reverseSort = new Array();
// Also, assume the team name column is initially sorted.
stColumn = 1;
}
// If this column has not been sorted before, set the initial sort direction.
if (tblEl.reverseSort[col] == null)
tblEl.reverseSort[col] = rev;
// If this column was the last one sorted, reverse its sort direction.
if (col == stColumn)
tblEl.reverseSort[col] = !tblEl.reverseSort[col];
// Remember this column as the last one sorted.
stColumn = col;
// Set the table display style to "none" - necessary for Netscape 6
// browsers.
var oldDsply = tblEl.style.display;
tblEl.style.display = "none";
// Sort the rows based on the content of the specified column using a