jquery實(shí)現(xiàn)的表格前端排序功能示例圖(jquery實(shí)現(xiàn)的表格前端排序功能示例是什么)

發(fā)布時(shí)間:2024-03-12
本文主要介紹jquery實(shí)現(xiàn)的表格前端排序功能示例圖(jquery實(shí)現(xiàn)的表格前端排序功能示例是什么),下面一起看看jquery實(shí)現(xiàn)的表格前端排序功能示例圖(jquery實(shí)現(xiàn)的表格前端排序功能示例是什么)相關(guān)資訊。
本文通過一個(gè)例子來描述用jquery實(shí)現(xiàn)的表格前端的排序功能。分享給你,供你參考,如下:
表格的前面按列排序。
依賴jquery(在這種情況下,使用jquery-1.8.2)
1.初始化方法
(函數(shù)($){ //插件$。extend($,{ //命名空間sort table : { sort :函數(shù)(tableid,idx){ var table = document . getelementbyid(table id);var tbody = table . tbodies[0];var tr = tbody.rowsvar tr value = new array;for(var i = 0;itr .長(zhǎng)度;i){ tr value[i]= tr[i];//將表格中每一行的信息存儲(chǔ)在新創(chuàng)建的數(shù)組中} if (tbody。sortcol = = idx) {trvalue。反向;//如果列已經(jīng)排序,直接逆序排列} else {trvalue。sort (function (tr1,tr2) {var value1 = tr1。細(xì)胞[idx]。innertext//column varvalue 2 = tr2 . cells[idx]。innertext//第二列value 1 = value 1 . replace( % , );//取消% value 1 = value 1 . trim;//white space console . log(type of(value 1));if(isnan(value 1)){ var index 1 = value 1。的索引積分 );var index 2 = value 2 . index of(積分 );if(index 10){ var num 1 = value 1 . substring(0,index 1);var num 2 = value 1 . substring(index 1 1,value 1 . length-1);var num3 =value2.substring(0,index 2);var num4 =value2.substring(索引2 1,值2 .長(zhǎng)度-1);if(parse float(num 1)parse float(num 3)){ return 1;} if(parse float(num 1)parse float(num 3)){ return-1;} if(parse float(num 1)= = parse float(num 3)){ return parse float(num 2)-parse float(num 4)} } else { var a = tr1 . cells[idx]。文本內(nèi)容;var b= tr2.cells[idx]。文本內(nèi)容;return a . locale compare(b);} } else { return parse float(value 1)-parse float(value 2);} });} var fragment = document . createdocumentfragment;//創(chuàng)建新的代碼片段保存排序后的結(jié)果//var index = 0;var arr total = new array;for(var i = 0;itrvalue.lengthi ) { var c = trvalue[i]。單元格[0]。innerhtml//console . log(c);if(c.trim。的索引總結(jié)與展望)!=-1){//匯總行總是在表的頂部//index = i;arr total . push(i);} else { fragment . appendchild(tr value[i]);} } if(arr total . length 0){ for(var k = arr total . length;k0;k-){ tbody . appendchild(tr value[arr total[k]]);} }//tbody . appendchild(tr value[index]);tbody.appendchild(片段);//用之前的值tbody.sortcol = idx替換排序后的結(jié)果;} } });})(jquery);2.頁面功能
函數(shù)desc_change(id,str){ $( # desc _ 1 ).超文本標(biāo)記語言( 日期和時(shí)間);$( # desc _ 2 ).html( id );$( # desc _ 3 ).html( 類別 );$( # id)。html(str);}函數(shù)desc(id,str){ var html str = $( # id)。文本。trim;var c = strif(html str = = str){ c = str ;↓ ;;$( # id)。html(c);} else if(html str = = str ;↓ ;){ c = str ↑ ;$( # id)。html(c);} else if(html str = = str ;↑ ;){ c = str ↓ ;$( # id)。html(c);} desc_change(id,c)}3。dom結(jié)構(gòu)
表id = 表排序和thead tr th onclick = $ . sort table . sort( ;表排序和。;,0);desc( ;desc _ 1 ;, 日期和時(shí)間。;) a id = desc _ 1 date/a/th onclick = $.排序表格。排序( 表格排序 , 1);desc( ;desc _ 2 ;, 軟件id ) a id = desc _ 2 id/a/thon click = $.排序表。排序( 表排序和。;, 2);desc( ;desc x ;頻道id ) a id = desc _ 3 cat《jquery表格(table)操作技巧匯總》、《jquery切換特效與技巧總結(jié)》、《jquery擴(kuò)展技巧總結(jié)》、《jquery常用插件及用法總結(jié)》、《jquery常見經(jīng)典特效匯總》、《jquery選擇器用法總結(jié)》。
希望這篇文章對(duì)你的jquery編程有所幫助。
標(biāo)簽:
排序表匯總的匯總技巧
了解更多jquery實(shí)現(xiàn)的表格前端排序功能示例圖(jquery實(shí)現(xiàn)的表格前端排序功能示例是什么)相關(guān)內(nèi)容請(qǐng)關(guān)注本站點(diǎn)。
上一個(gè):打游戲筆記本哪款好(打游戲筆記本電腦推薦)
下一個(gè):win7怎么格式化移動(dòng)硬盤數(shù)據(jù)(win7格式化移動(dòng)硬盤怎么沒有exFAT選項(xiàng))

嵌入式處理器
風(fēng)聲過了 余茶水一樣的落寂
醫(yī)療事故賠償?shù)脑瓌t是什么
飲用菊花茶要牢記的宜忌
win7怎么調(diào)屏幕飽和度(windows7怎么調(diào)飽和度)
win11檢測(cè)工具官網(wǎng)(win11檢測(cè)工具怎么下載)
積極解決夏茬花生地膜覆蓋中的新問題
什么時(shí)候才是喝白茶的最佳時(shí)機(jī)?
云服務(wù)IPv6支持能力測(cè)評(píng)項(xiàng)目發(fā)布 四家服務(wù)商通過測(cè)評(píng)
照度儀概述
十八禁 网站在线观看免费视频_2020av天堂网_一 级 黄 色 片免费网站_绝顶高潮合集Videos