午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    js表頭排序?qū)崿F(xiàn)方法
    來源:易賢網(wǎng) 閱讀:760 次 日期:2016-06-17 09:42:07
    溫馨提示:易賢網(wǎng)小編為您整理了“js表頭排序?qū)崿F(xiàn)方法”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了js表頭排序?qū)崿F(xiàn)方法,涉及數(shù)字、字母、字符串比較及排序等操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

    本文實(shí)例講述了js表頭排序?qū)崿F(xiàn)方法。分享給大家供大家參考。

    具體實(shí)現(xiàn)方法如下:

    代碼如下:

    <script type=text/javascript>

    //是否遞減排序

    var isdescending = true;

    /*****************************************

    * 要排序的行必須放到<tbody></tbody>標(biāo)簽中

    * tableid:排序表格id

    * colno:排序的列號(hào),即第幾列,從0開始

    * startrowno:排序的開始行號(hào),從0開始

    * sortlength:要排序的行數(shù),

    * type:排序列的類型

    */

    function sort(tableid, colno ,startrowno, sortlength, type)

    {

    //如果要排序的行數(shù)是1或是0,則不對(duì)其進(jìn)行排序操作

    if(sortlength<=1){

    return;

    }

    var currtable = document.getelementbyid(tableid);

    var theheader = currtable.outerhtml.substring(0, currtable.outerhtml.indexof('<tbody>')+7)

    var thefooter = currtable.outerhtml.substring(currtable.outerhtml.indexof('</tbody>')-8);

    //這里的行數(shù)是去掉表頭表頭行和表位行的行數(shù)

    var therows = new array(sortlength);

    //對(duì)表中的數(shù)據(jù)進(jìn)行循環(huán)

    for(i=startrowno; i<sortlength+startrowno; i++)

    {

    therows[i-startrowno] = new array(currtable.rows[i].cells[colno].innertext.tolowercase(), currtable.rows[i].outerhtml);

    }

    if(type.touppercase()=='number')

    {

    therows.sort(comparenumber);

    }

    else if(type.touppercase()=='date')

    therows.sort(comparedate);

    else if(type.touppercase()=='string')

    therows.sort(comparestring);

    var tableinfo=''

    for(j=0; j<therows.length; j++)

    {

    tableinfo+=therows[j][1];

    }

    isdescending = !isdescending;

    currtable.outerhtml= theheader + tableinfo +thefooter;

    return ;

    }

    //對(duì)數(shù)字進(jìn)行比較

    function comparenumber(x, y)

    {

    //對(duì)貨幣格式的數(shù)據(jù)進(jìn)行轉(zhuǎn)化

    a = x[0].excludechars(,).trim();

    b = y[0].excludechars(,).trim();

    if(a==){a=0;}

    if(b==){b=0;}

    if(isdescending)

    {

    return parsefloat(b) - parsefloat(a);

    }

    else

    {

    return parsefloat(a) - parsefloat(b);

    }

    }

    //對(duì)字符串進(jìn)行比較

    function comparestring(x, y)

    {

    if(isdescending)

    {

    if(x[0]>y[0]) return -1;

    else if(x[0]<y[0]) return 1;

    else return 0;

    }

    else

    {

    if(x[0]<y[0]) return -1;

    else if(x[0]>y[0]) return 1;

    else return 0;

    }

    }

    //對(duì)時(shí)間進(jìn)行比較

    function comparedate(x,y){

    var arr=x[0].split(-);

    var starttime=new date(arr[0],arr[1],arr[2]);

    var starttimes=starttime.gettime();

    var arrs=y[0].split(-);

    var lktime=new date(arrs[0],arrs[1],arrs[2]);

    var lktimes=lktime.gettime();

    if(isdescending)

    {

    return lktimes - starttimes;

    }

    else

    {

    return starttimes - lktimes;

    }

    }

    //去除字符串中所有指定的字符串

    string.prototype.excludechars = function(chars){

    var matching = new regexp(chars , g) ;

    return this.replace(matching , '') ;

    }

    </script>

    希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

    更多信息請(qǐng)查看腳本欄目
    易賢網(wǎng)手機(jī)網(wǎng)站地址:js表頭排序?qū)崿F(xiàn)方法
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)