国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

用于table內(nèi)容排序_javascript技巧

來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 20:32:55
文檔

用于table內(nèi)容排序_javascript技巧

用于table內(nèi)容排序_javascript技巧:sort tablea { color:#000000; font-weight: bold; text-decoration: none;}點(diǎn)擊標(biāo)題排序 Name Salary Extension Start date Bloggs, Fred $12000.00 1353 18/08/2003 Turvey, Kevin $191200
推薦度:
導(dǎo)讀用于table內(nèi)容排序_javascript技巧:sort tablea { color:#000000; font-weight: bold; text-decoration: none;}點(diǎn)擊標(biāo)題排序 Name Salary Extension Start date Bloggs, Fred $12000.00 1353 18/08/2003 Turvey, Kevin $191200





sort table




點(diǎn)擊標(biāo)題排序















































Name Salary Extension Start date
Bloggs, Fred $12000.00 1353 18/08/2003
Turvey, Kevin $191200.00 2342 02/05/1979
Mbogo, Arnold $32010.12 2755 09/08/1998
Shakespeare, Bill $122000.00 3211 12/11/1961
Shakespeare, Hamnet $9000 9005 01/01/2002
Fitz, Marvin $3300 5554 22/05/1995

Alpha's blog



代碼如下:

addEvent(window, "load", sortables_init);

var SORT_COLUMN_INDEX;

function sortables_init() {
// Find all tables with class sortable and make them sortable
if (!document.getElementsByTagName) return;
tbls = document.getElementsByTagName("table");
for (ti=0;ti thisTbl = tbls[ti];
if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) {
//initTable(thisTbl.id);
ts_makeSortable(thisTbl);
}
}
}

function ts_makeSortable(table) {
if (table.rows && table.rows.length > 0) {
var firstRow = table.rows[0];
}
if (!firstRow) return;

// We have a first row: assume it's the header, and make its contents clickable links
for (var i=0;i var cell = firstRow.cells[i];
var txt = ts_getInnerText(cell);
cell.innerHTML = ' 'onclick="ts_resortTable(this, '+i+');return false;">' +
txt+'';
}
}

function ts_getInnerText(el) {
if (typeof el == "string") return el;
if (typeof el == "undefined") { return el };
if (el.innerText) return el.innerText; //Not needed but it is faster
var str = "";

var cs = el.childNodes;
var l = cs.length;
for (var i = 0; i < l; i++) {
switch (cs[i].nodeType) {
case 1: //ELEMENT_NODE
str += ts_getInnerText(cs[i]);
break;
case 3: //TEXT_NODE
str += cs[i].nodeValue;
break;
}
}
return str;
}

function ts_resortTable(lnk,clid) {
// get the span
var span;
for (var ci=0;ci if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
}
var spantext = ts_getInnerText(span);
var td = lnk.parentNode;
var column = clid || td.cellIndex;
var table = getParent(td,'TABLE');

// Work out a type for the column
if (table.rows.length <= 1) return;
var itm = ts_getInnerText(table.rows[1].cells[column]);
sortfn = ts_sort_caseinsensitive;
if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
if (itm.match(/^[$]/)) sortfn = ts_sort_currency;
if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
SORT_COLUMN_INDEX = column;
var firstRow = new Array();
var newRows = new Array();
for (i=0;i for (j=1;j

newRows.sort(sortfn);

if (span.getAttribute("sortdir") == 'down') {
ARROW = '↑';
newRows.reverse();
span.setAttribute('sortdir','up');
} else {
ARROW = '↓';
span.setAttribute('sortdir','down');
}

// We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
// don't do sortbottom rows
for (i=0;i // do sortbottom rows only
for (i=0;i // Delete any other arrows there may be showing
var allspans = document.getElementsByTagName("span");
for (var ci=0;ci if (allspans[ci].className == 'sortarrow') {
if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
allspans[ci].innerHTML = '';
}
}
}

span.innerHTML = ARROW;
}

function getParent(el, pTagName) {
if (el == null) return null;
else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) // Gecko bug, supposed to be uppercase
return el;
else
return getParent(el.parentNode, pTagName);
}
function ts_sort_date(a,b) {
// y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
if (aa.length == 10) {
dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
} else {
yr = aa.substr(6,2);
if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
}
if (bb.length == 10) {
dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
} else {
yr = bb.substr(6,2);
if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
}
if (dt1==dt2) return 0;
if (dt1 return 1;
}

function ts_sort_currency(a,b) {
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
return parseFloat(aa) - parseFloat(bb);
}

function ts_sort_numeric(a,b) {
aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
if (isNaN(aa)) aa = 0;
bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX]));
if (isNaN(bb)) bb = 0;
return aa-bb;
}

function ts_sort_caseinsensitive(a,b) {
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
if (aa==bb) return 0;
if (aa return 1;
}

function ts_sort_default(a,b) {
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
if (aa==bb) return 0;
if (aa return 1;
}


function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+, NS6 and Mozilla
// By Scott Andrew
{
if (elm.addEventListener){
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent){
var r = elm.attachEvent("on"+evType, fn);
return r;
} else {
alert("Handler could not be removed");
}
}

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

用于table內(nèi)容排序_javascript技巧

用于table內(nèi)容排序_javascript技巧:sort tablea { color:#000000; font-weight: bold; text-decoration: none;}點(diǎn)擊標(biāo)題排序 Name Salary Extension Start date Bloggs, Fred $12000.00 1353 18/08/2003 Turvey, Kevin $191200
推薦度:
標(biāo)簽: js 排序 javascript
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 91精品国产91热久久p | 亚洲一区二区综合 | 欧美日韩国产一区二区三区播放 | 日韩毛毛片 | 国产成人一区二区三区 | 欧美综合国产精品日韩一 | 国产区二区 | 在线 | 一区二区三区 | 在线国产日韩 | 亚洲国产成人久久一区久久 | 亚洲另类第一页 | 国产成人亚洲欧美三区综合 | 午夜操一操 | 亚欧日韩 | 欧美高清第一页 | 国产日韩一区二区三区在线观看 | 国产第一页在线视频 | 日韩电影免费在线观看中文字幕 | 久久精品最新免费国产成人 | 久久免费福利视频 | 可以免费观看的毛片 | 欧美激情 在线 | 在线观看亚洲 | 日韩国产另类 | 国产一区二区久久久 | 免费不卡视频 | 国产精品福利久久久久久小说 | 国产高清一区二区三区 | 国产黄色片在线观看 | 国产区最新| 欧美视频区| 国产美女视频黄a视频免费全过程 | 一二三高清区线路1 | 国产丝袜在线视频 | 一级网站在线观看 | 看全色黄大色黄女片爽毛片 | 国模双双大尺度炮交g0go | 亚洲伊人久久大香线蕉综合图片 | 一本久道久久综合 | xx日韩| 亚洲欧美综合 |