0

「テーブル」ではなく「テーブル ID」で呼び出して要素をソートするように、誰かがこの JQuery コードを変更するのを手伝ってくれることを願っています。問題は、ページに複数のテーブルが含まれており、ID で識別される 1 つの特定のテーブルに基づいてテーブルの並べ替えを機能させたいということです。これは、Jquery Sort Elements プラグインを使用して機能します。何か案は?

https://raw.github.com/padolsey/jQuery-Plugins/master/sortElements/jquery.sortElements.js

$(window).load(function(){
    var table = $('table');

    $('#facility_header, #city_header')
        .wrapInner('<span title="sort this column"/>')
        .each(function(){

            var th = $(this),
                thIndex = th.index(),
                inverse = false;

            th.click(function(){

                table.find('td').filter(function(){

                    return $(this).index() === thIndex;

                }).sortElements(function(a, b){

                    return $.text([a]) > $.text([b]) ?
                        inverse ? -1 : 1
                        : inverse ? 1 : -1;

                }, function(){

                    // parentNode is the element we want to move
                    return this.parentNode; 

                });

                inverse = !inverse;

            });

        });

});//]]>  
4

1 に答える 1

1

この部分を変えるだけ

var table = $('#tableid');

jqueryセレクターの詳細はこちらhttp://api.jquery.com/category/selectors/

于 2012-05-03T17:17:49.950 に答える