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

This should be outside of your function :

//  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");
});

And complete code look like this:

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>

Something wrong with your :

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

review your tablesorter()

于 2013-11-01T04:16:56.803 回答