2

フェーズ 2 として最新バージョンに更新する計画で、サイトを jQuery 1.7 に更新中です。以下は、テーブルの並べ替え機能を維持するために .on() に更新する必要がある既存の livequery コードです。

// EXISTING CODE - Applies table sorting to existing and future tables with class of tablesorter
$("table.tablesorter").livequery(function(){ // need to replace this .livequery code

このコードを使用して、DOM がロードされたときに存在するテーブルでテーブルの並べ替えを有効にできますが、DOM がロードされた後に作成されたテーブルでは機能しません。

// Only works on existing tables
$('table.tablesorter').tablesorter();

.on で次のコードを試しましたが、最初のクリックに反応しません

// Works on existing tables and tables created later, but it will not respond to initial click event
$(document).on('click', 'table.tablesorter', function(e){  $('table.tablesorter').tablesorter(); });

どんな推奨事項も大歓迎です。

4

1 に答える 1

0

ajaxを使用してテーブルデータをロードしている場合は、コールバック関数(またはdone以下に示す関数;デモ)でテーブルを初期化するだけです。

$.ajax({
  type: "GET",
  // should return raw html of the table
  url: "mysite.com/table"
}).done(function(data) {
  // add the table
  $(data).appendTo('body');
  // initialize it
  $('table').tablesorter({
    theme : 'blue'
  });
});

これは多くの例の1つにすぎません。

于 2013-03-19T23:30:05.100 に答える