




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
具备排序功能的表格(JS+CSS+table)-TABLE BORDER-RIGHT: #000000 2px solid; BORDER-TOP: #000000 2px solid; BORDER-LEFT: #000000 2px solid; BORDER-BOTTOM: #000000 2px solid; border-spacing: 0px; cell-spacing: 0pxTD PADDING-RIGHT: 0.5em; PADDING-LEFT: 0.5em; FONT-SIZE: 10pt; PADDING-BOTTOM: 2px; PADDING-TOP: 2px; FONT-FAMILY: Arial, Helvetica, sans-serif; WHITE-SPACE: nowrapTH PADDING-RIGHT: 0.5em; PADDING-LEFT: 0.5em; FONT-SIZE: 10pt; PADDING-BOTTOM: 2px; PADDING-TOP: 2px; FONT-FAMILY: Arial, Helvetica, sans-serif; WHITE-SPACE: nowrapTD.numeric TEXT-ALIGN: rightTH BACKGROUND-COLOR: #c0c0c0TH.mainHeader COLOR: #ffffff; BACKGROUND-COLOR: #808080; TEXT-ALIGN: leftTH A COLOR: #000080; TEXT-DECORATION: noneTH A:visited COLOR: #000080TH A:active COLOR: #800000; TEXT-DECORATION: underlineTH A:hover COLOR: #800000; TEXT-DECORATION: underlineTR.alternateRow BACKGROUND-COLOR: #e0e0e0TD.sortedColumn BACKGROUND-COLOR: #f0f0f0TH.sortedColumn BACKGROUND-COLOR: #b0b0b0TR.alternateRow TD.sortedColumn BACKGROUND-COLOR: #d0d0d0/-/ 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.tblEl.lastColumn = 1;/ If this column has not been sorted before, set the initial sort direction.if (tblEl.reverseSortcol = null)tblEl.reverseSortcol = rev;/ If this column was the last one sorted, reverse its sort direction.if (col = tblEl.lastColumn)tblEl.reverseSortcol = !tblEl.reverseSortcol;/ Remember this column as the last one sorted.tblEl.lastColumn = 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/ selection sort.var tmpEl;var i, j;var minVal, minIdx;var testVal;var cmp;for (i = 0; i tblEl.rows.length - 1; i+) / Assume the current row has the minimum value.minIdx = i;minVal = getTextValue(tblEl.rowsi.cellscol);/ Search the rows that follow the current one for a smaller value.for (j = i + 1; j 0) minIdx = j;minVal = testVal;/ By now, we have the row with the smallest value. Remove it from the/ table and insert it before the current row.if (minIdx i) tmpEl = tblEl.removeChild(tblEl.rowsminIdx);tblEl.insertBefore(tmpEl, tblEl.rowsi);/ Make it look pretty.makePretty(tblEl, col);/ Set team rankings.setRanks(tblEl, col, rev);/ Restore the tables display style.tblEl.style.display = oldDsply;return false;/-/ Functions to get and compare values during a sort./-/ This code is necessary for browsers that dont reflect the DOM constants/ (like IE).if (document.ELEMENT_NODE = null) document.ELEMENT_NODE = 1;document.TEXT_NODE = 3;function getTextValue(el) var i;var s;/ Find and concatenate the values of all text nodes contained within the/ element.s = ;for (i = 0; i v2)return 1return -1;/ Regular expressions for normalizing white space.var whtSpEnds = new RegExp(s*|s*$, g);var whtSpMult = new RegExp(ss+, g);function normalizeString(s) s = s.replace(whtSpMult, ); / Collapse any multiple whites space.s = s.replace(whtSpEnds, ); / Remove leading or trailing white space.return s;/-/ Functions to update the table appearance after a sort./-/ Style class names.var rowClsNm = alternateRow;var colClsNm = sortedColumn;/ Regular expressions for setting class names.var rowTest = new RegExp(rowClsNm, gi);var colTest = new RegExp(colClsNm, gi);function makePretty(tblEl, col) var i, j;var rowEl, cellEl;/ Set style classes on each row to alternate their appearance.for (i = 0; i tblEl.rows.length; i+) rowEl = tblEl.rowsi;rowEl.className = rowEl.className.replace(rowTest, );if (i % 2 != 0)rowEl.className += + rowClsNm;rowEl.className = normalizeString(rowEl.className);/ Set style classes on each column (other than the name column) to/ highlight the one that was sorted.for (j = 2; j tblEl.rowsi.cells.length; j+) cellEl = rowEl.cellsj;cellEl.className = cellEl.className.replace(colTest, );if (j = col)cellEl.className += + colClsNm;cellEl.className = normalizeString(cellEl.className);/ Find the table header and highlight the column that was sorted.var el = tblEl.parentNode.tHead;rowEl = el.rowsel.rows.length - 1;/ Set style classes for each column as above.for (i = 2; i 1 & i = 0 & i tblEl.rows.length) / Get the value of the sort column in this row.curVal = getTextValue(tblEl.rowsi.cellscol);/ On rows after the first, compare the sort value of this row to the/ previous one. If they differ, update the rank to match the current row/ count. (If they are the same, this row will get the same rank as the/ previous one.)if (lastVal != null & compareValues(curVal, lastVal) != 0)rank = count;/ Set the rank for this row.tblEl.rowsi.rank = rank;/ Save the sort value of the current row for the next time around and bump/ the row counter and index.lastVal = curVal;count+;i += incr;/ Now go through each row (from top to bottom) and display its rank. Note/ that when two or more rows are tied, the rank is shown on the first of/ those rows only.var rowEl, cellEl;var lastRank = 0;/ Go through the rows from top to bottom.for (i = 0; i 1 & rowEl.rank != lastRank) cellEl.appendChild(document.createTextNode(rowEl.rank);lastRank = rowEl.rank;懒人建站RankTeamGmsYdsYds/GRuYdsRuYds/GPaYdsPaYds/GPtsPts/GArizona164898306.1144990.63449215.629518.4Atlanta165070316.91773110.83297206.129118.2Baltimore164773318.21598106.53175211.728418.9Buffalo165137321.11686105.43451215.726516.6Carolina164254265.9137285.82882180.125315.8Chicago164694293.4174210
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年临沂郯城县教育系统部分事业单位公开招聘教师(13名)考前自测高频考点模拟试题及答案详解(典优)
- 2025年福建省福州市闽清县机关事务服务中心招聘1人模拟试卷及完整答案详解
- 2025年江西省中小学教师及特岗教师招聘笔试赣州考区考前自测高频考点模拟试题及答案详解(易错题)
- 2025年衢州常山县公开招聘专职社区工作者12人考前自测高频考点模拟试题带答案详解
- 2025湖南湘江爱乐乐团招聘考前自测高频考点模拟试题及完整答案详解1套
- 2025年吉林省高速公路集团有限公司长春分公司劳务派遣项目招聘(4人)考前自测高频考点模拟试题及一套参考答案详解
- 2025江苏盐城市射阳县商务局等单位招聘政府购买服务人员招聘计划核销模拟试卷附答案详解(典型题)
- 2025广西百色市右江民族医学院招聘实名编制高层次人才模拟试卷及答案详解(典优)
- 2025年宁夏电力投资集团有限公司春季校园招聘开始啦模拟试卷及答案详解(典优)
- 2025广东韶关市浈江区社区专职工作人员招聘27人模拟试卷有完整答案详解
- 钻探工(高级)职业技能考试题(附答案)
- 锂电池、新能源汽车火灾事故灭火救援处置
- 《公路技术状况评定》课件-任务六:公路技术状况指数MQI
- 油气输送管道穿越工程施工规范
- 酒店客房入住数据分析表格
- 中级财务会计知到课后答案智慧树章节测试答案2025年春云南财经大学
- 2025青海省建筑安全员B证考试题库及答案
- 新版机动车交通事故责任强制保险合同
- 临床检验基础知到智慧树章节测试课后答案2024年秋上海健康医学院
- 铸牢中华民族共同体意识心得感悟7篇
- 《中国海洋大学》课件
评论
0/150
提交评论