<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題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關鍵字專題關鍵字專題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
        當前位置: 首頁 - 科技 - 知識百科 - 正文

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

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

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

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





        sort table




        點擊標題排序















































        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)容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。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;}點擊標題排序 Name Salary Extension Start date Bloggs, Fred $12000.00 1353 18/08/2003 Turvey, Kevin $191200
        推薦度:
        標簽: js 排序 javascript
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 99在线观看视频免费| 一区二区三区在线免费看| 亚洲av片劲爆在线观看| 亚洲天堂免费在线视频| 亚洲AⅤ无码一区二区三区在线 | 亚洲欧洲国产精品你懂的| 今天免费中文字幕视频| 亚洲av无码成h人动漫无遮挡| 亚洲中文字幕久久精品无码2021| 最近中文字幕mv免费高清视频8 | 久久精品九九亚洲精品| 在线视频精品免费| 久久精品国产亚洲AV久| 日本无吗免费一二区| 免费人妻精品一区二区三区| 亚洲免费日韩无码系列| 日本在线免费观看| avtt亚洲天堂| 怡红院免费的全部视频| 亚洲美女aⅴ久久久91| 女人18毛片特级一级免费视频| 亚洲成AV人片在WWW| 国产亚洲人成网站在线观看| 国产成人免费ā片在线观看老同学 | 日本免费高清视频| 亚洲一级免费视频| 国产免费啪嗒啪嗒视频看看| 亚洲一区二区三区久久久久| 免费观看的a级毛片的网站| 亚洲精品国产日韩无码AV永久免费网| 国产亚洲一区二区三区在线| 亚洲成年人免费网站| 美女露隐私全部免费直播| 拨牐拨牐x8免费| 久久久久亚洲精品无码蜜桃| 美女被免费视频网站a国产| 永久在线观看免费视频| 亚洲中文字幕久久无码| 日韩亚洲欧洲在线com91tv| 国产精品免费观看久久| 国产中文字幕在线免费观看|