本文实例为大家分享了JavaScript实现HTML表格排序功能,供大家参考,具体内容如下

HTML代码:

<table cellpadding="0" id="table">
    <tr class="top">
      <td>click me</td>
      <td>click me</td>
      <td>click me</td>
      <td>click me</td>
    </tr>
    <tr>
      <td>
        <span id="bfn_la_bac.usa">15.43</span>
      </td>
      <td class="red">700</td>
      <td>1.220</td>
      <td class="red">阿</td>
    </tr>
    <tr>
      <td>
        <span id="bfn_la_c.usa">7.05</span>
      </td>
      <td class="red">4</td>
      <td>3,000</td>
      <td class="red">炳</td>
    </tr>
    <tr>
      <td>
        <span id="bfn_la_jpm.usa">30.62</span>
      </td>
      <td class="red">30</td>
      <td>2,558,800</td>
      <td class="red">和</td>
    </tr>
    <tr>
      <td>
        <span id="bfn_la_axp.usa">22.30</span>
      </td>
      <td class="red">5</td>
      <td>6</td>
      <td class="red">瞎</td>
    </tr>
    <tr>
      <td>
        <span id="bfn_la_mrk.usa">26.31</span>
      </td>
      <td class="red">0.6</td>
      <td>5</td>
      <td class="red">-</td>
    </tr>
    <tr>
      <td>
        <span id="bfn_la_pg.usa">63.16</span>
      </td>
      <td class="red">7</td>
      <td>4</td>
      <td class="red">子</td>
    </tr>
  </table>

JavaScirpt代码:

var tableSort = function(){ 
  this.initialize.apply(this,arguments); 
} 
tableSort.prototype = { 
  initialize : function(tableId,clickRow,startRow,endRow,classUp,classDown,selectClass){ 
    this.Table = document.getElementById(tableId); 
    this.rows = this.Table.rows;//所有行 
    this.Tags = this.rows[clickRow-1].cells;//标签td 
    this.up = classUp; 
    this.down = classDown; 
    this.startRow = startRow; 
    this.selectClass = selectClass; 
    this.endRow = (endRow == 999" "+className; 
  } 
} 
function removeClass(element, className) { 
  if (hasClass(element, className)) { 
    var reg = new RegExp('(\s|^)'+className+'(\s|$)'); 
    element.className = element.className.replace(reg,' '); 
  } 
} 
var Bind = function(object, fun) { 
  return function() { 
    return fun.apply(object, arguments); 
  } 
} 
//去掉所有的html标记 
function killHTML(str){ 
  return str.replace(/<[^>]+>/g,""); 
} 
//------------------------------------------------ 
//tableid 第几行是标签行,从第几行开始排序,第几行结束排序(999表示最后) 升序标签样式,降序标签样式 选中列样式 
//注意标签行的class应该是一致的 
var ex1 = new tableSort('table',1,2,999,'up','down','hov');

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
js实现表格排序,jquery实现表格排序,html表格排序,html表格数据排序

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“JS实现HTML表格排序功能”

暂无“JS实现HTML表格排序功能”评论...