0

テーブルをソート可能にするためにjquery関数を実行しようとしています。呼び出されますが、戻りません。なぜそれが考えられるのですか?

function makeTableSortable() {
  alert('mts called');
  //Credit to: http://www.pewpewlaser.com/articles/jquery-tablesorter
  //
  //  Adds sort_header class to ths
  $(".sortable th").addClass("sort_header");

  //  Adds alternating row coloring to table.
  $(".sortable").tablesorter({widgets: ["zebra"]});

  //  Adds "over" class to rows on mouseover
  $(".sortable tr").mouseover(function() {
      $(this).addClass("over");
  });

  //  Removes "over" class from rows on mouseout
  $(".sortable tr").mouseout(function() {
    $(this).removeClass("over");
  });
  alert('mts done!');
}
4

1 に答える 1

1

これは関数の外にある必要があります:

//  Adds "over" class to rows on mouseover
$(".sortable tr").mouseover(function() {
    $(this).addClass("over");
});

//  Removes "over" class from rows on mouseout
$(".sortable tr").mouseout(function() {
    $(this).removeClass("over");
});

完全なコードは次のようになります。

function makeTableSortable() {
alert('mts called');
//Credit to: http://www.pewpewlaser.com/articles/jquery-tablesorter
//
//  Adds sort_header class to ths
$(".sortable th").addClass("sort_header");

//  Adds alternating row coloring to table.
$(".sortable").tablesorter({widgets: ["zebra"]});
alert('mts done!');
}


$(document).ready(function(e) {
    //  Adds "over" class to rows on mouseover
    $(".sortable tr").mouseover(function() {
        $(this).addClass("over");
    });

    //  Removes "over" class from rows on mouseout
    $(".sortable tr").mouseout(function() {
        $(this).removeClass("over");
    });
}
    </script>

あなたの何かが間違っています:

$(".sortable").tablesorter({widgets: ["zebra"]});

あなたのレビュー tablesorter()

于 2013-11-01T04:16:56.803 に答える