我正在尝试运行一个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!');
}
答案 0 :(得分: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()