最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

TableSort.js表格排序插件使用方法詳解

 更新時間:2017年02月10日 13:55:59   作者:孫瑞  
這篇文章主要為大家詳細(xì)介紹了TableSort.js表格排序插件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了TableSort.js表格排序的具體代碼,供大家參考,具體內(nèi)容如下

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>TableSort</title> 
<style type="text/css"> 
table { 
  border-collapse: collapse; 
  width: 300px; 
} 
table caption { 
  border-right: 1px solid #abc; 
  border-left: 1px solid #abc; 
  border-top: 2px solid #000; 
  border-bottom: 2px solid #000; 
  background-color: #afd; 
} 
#sales tr, #sales td { 
  border: 1px solid #abc; 
  text-align: center; 
} 
</style> 
</head> 
<body> 
<table id="sales" summary="summary here"> 
 <caption> 
 Main Title 
 </caption> 
 <col/> 
 <col/> 
 <col/> 
 <thead> 
  <tr> 
   <th class="asc">Col1</th> 
   <th>Col2</th> 
   <th>Col3</th> 
  </tr> 
 </thead> 
 <tbody> 
  <tr> 
   <td>A1</td> 
   <td>S2</td> 
   <td>W3</td> 
  </tr> 
  <tr> 
   <td>B1</td> 
   <td>C2</td> 
   <td>V3</td> 
  </tr> 
  <tr> 
   <td>C1</td> 
   <td>X2</td> 
   <td>K3</td> 
  </tr> 
 </tbody> 
 <!-- tfoot><tr><td cols=3 >other description</td></tr></tfoot --> 
</table> 
<button onclick="fn()">Test</button> 
<script language="javascript"> 
function TableSort(id) { 
  this.tbl = document.getElementById(id); 
  this.lastSortedTh = null; 
  if (this.tbl && this.tbl.nodeName == "TABLE") { 
    var headings = this.tbl.tHead.rows[0].cells; 
    for (var i = 0; headings[i]; i++) { 
      if (headings[i].className.match(/asc|dsc/)) { 
        this.lastSortedTh = headings[i]; 
      } 
    } 
    this.makeSortable(); 
  } 
} 
TableSort.prototype.makeSortable = function() { 
  var headings = this.tbl.tHead.rows[0].cells; 
  for (var i = 0; headings[i]; i++) { 
    headings[i].cIdx = i; 
    var a = document.createElement("a"); 
    a.href = "#"; 
    a.innerHTML = headings[i].innerHTML; 
    a.onclick = function(that) { 
      return function() { 
        that.sortCol(this); 
        return false; 
      } 
    }(this); 
    headings[i].innerHTML = ""; 
    headings[i].appendChild(a); 
  } 
} 
TableSort.prototype.sortCol = function(el) { 
  var rows = this.tbl.rows; 
  var alpha = [], numeric = []; 
  var aIdx = 0, nIdx = 0; 
  var th = el.parentNode; 
  var cellIndex = th.cIdx; 
 
  for (var i = 1; rows[i]; i++) { 
    var cell = rows[i].cells[cellIndex]; 
    var content = cell.textContent ? cell.textContent : cell.innerText; 
    var num = content.replace(/(\$|\,|\s)/g, ""); 
    if (parseFloat(num) == num) { 
      numeric[nIdx++] = { 
        value : Number(num), 
        row : rows[i] 
      } 
    } else { 
      alpha[aIdx++] = { 
        value : content, 
        row : rows[i] 
      } 
    } 
  } 
  function bubbleSort(arr, dir) { 
    var start, end; 
    if (dir === 1) { 
      start = 0; 
      end = arr.length; 
    } else if (dir === -1) { 
      start = arr.length - 1; 
      end = -1; 
    } 
    var unsorted = true; 
    while (unsorted) { 
      unsorted = false; 
      for (var i = start; i != end; i = i + dir) { 
        if (arr[i + dir] && arr[i].value > arr[i + dir].value) { 
          var temp = arr[i]; 
          arr[i] = arr[i + dir]; 
          arr[i + dir] = temp; 
          unsorted = true; 
        } 
      } 
    } 
    return arr; 
  } 
 
  var col = [], top, bottom; 
  if (th.className.match("asc")) { 
    top = bubbleSort(alpha, -1); 
    bottom = bubbleSort(numeric, -1); 
    th.className = th.className.replace(/asc/, "dsc"); 
  } else { 
    top = bubbleSort(numeric, 1); 
    bottom = bubbleSort(alpha, 1); 
    if (th.className.match("dsc")) { 
      th.className = th.className.replace(/dsc/, "asc"); 
    } else { 
      th.className += "asc"; 
    } 
  } 
  if (this.lastSortedTh && th != this.lastSortedTh) { 
    this.lastSortedTh.className = this.lastSortedTh.className.replace( 
        /dsc|asc/g, ""); 
  } 
  this.lastSortedTh = th; 
  col = top.concat(bottom); 
  var tBody = this.tbl.tBodies[0]; 
  for (var i = 0; col[i]; i++) { 
    tBody.appendChild(col[i].row); 
  } 
} 
function fn() { 
 
  var sales = document.getElementById('sales'); 
  var sortTable = new TableSort('sales'); 
} 
</script> 
</body> 
</html> 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript新增樣式規(guī)則(推薦)

    JavaScript新增樣式規(guī)則(推薦)

    這篇文章主要介紹了JavaScript新增樣式規(guī)則(推薦)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • Uniapp實現(xiàn)下拉刷新的三種方式

    Uniapp實現(xiàn)下拉刷新的三種方式

    在小程序、h5等地方中,常常會用到下拉刷新這個功能,今天來講解實現(xiàn)這個功能的三種方式:全局下拉刷新,組件局部下拉刷新,嵌套組件下拉刷新,,文中通過代碼示例講解的非常詳細(xì),需要的朋友可以參考下
    2025-02-02
  • 基于layui框架響應(yīng)式布局的一些使用詳解

    基于layui框架響應(yīng)式布局的一些使用詳解

    今天小編就為大家分享一篇基于layui框架響應(yīng)式布局的一些使用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-09-09
  • ElementUI el-switch 使用示例詳解

    ElementUI el-switch 使用示例詳解

    在這篇文章中,我們詳細(xì)介紹了 ElementUI 的 el-switch 組件,從基本用法到高級應(yīng)用,以及其背后的實現(xiàn)原理,需要的朋友可以參考下
    2024-08-08
  • JavaScript仿微信打飛機(jī)游戲

    JavaScript仿微信打飛機(jī)游戲

    這篇文章主要為大家詳細(xì)介紹了JavaScript仿微信打飛機(jī)游戲的相關(guān)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 小程序?qū)崿F(xiàn)輪播每次顯示三條數(shù)據(jù)

    小程序?qū)崿F(xiàn)輪播每次顯示三條數(shù)據(jù)

    這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)輪播每次顯示三條數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • three.js 制作動態(tài)二維碼的示例代碼

    three.js 制作動態(tài)二維碼的示例代碼

    這篇文章主要介紹了three.js 制作動態(tài)二維碼的示例代碼,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • 讓AJAX不依賴后端接口實現(xiàn)方案

    讓AJAX不依賴后端接口實現(xiàn)方案

    網(wǎng)頁中的ajax請求越來越多,或者應(yīng)用開始就一直使用ajax與后端進(jìn)行數(shù)據(jù)交換,本文將詳細(xì)介紹,需要的朋友可以參考下
    2012-12-12
  • 純js代碼實現(xiàn)未知寬高的元素在指定元素中垂直水平居中顯示

    純js代碼實現(xiàn)未知寬高的元素在指定元素中垂直水平居中顯示

    本章節(jié)介紹一下如何實現(xiàn)未知寬高的元素在指定元素下實現(xiàn)垂直水平居中效果,代碼簡單易懂,需要的朋友可以參考下本文
    2015-09-09
  • layui2.0使用table+laypage實現(xiàn)真分頁

    layui2.0使用table+laypage實現(xiàn)真分頁

    這篇文章主要為大家詳細(xì)介紹了layui2.0使用table+laypage實現(xiàn)真分頁,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07

最新評論

灵璧县| 新巴尔虎左旗| 紫金县| 昆山市| 文成县| 锦屏县| 晋州市| 德惠市| 周宁县| 卫辉市| 灵石县| 江华| 通辽市| 永年县| 张掖市| 介休市| 曲沃县| 天柱县| 库车县| 炉霍县| 桂平市| 佛学| 双辽市| 惠州市| 武宁县| 朝阳区| 南乐县| 栾城县| 大理市| 五台县| 宁德市| 榆树市| 宿州市| 义乌市| 郓城县| 建昌县| 甘肃省| 陕西省| 墨竹工卡县| 杭锦旗| 桑日县|