我有一个使用 tablesorter 插件成功排序的表。但是,我想突出显示特定行中特定文本字段中的文本。它有一个唯一的 ID,但是当我将代码放在排序代码之后时,它不起作用。这是我的代码:
jQuery(document).ready(function() {
jQuery("#filetable").tablesorter({
sortList: [[3,1]],
widgets: ['zebra'],
testExtraction: "complex"
});
//my new code which doesn't work as expected
if(jQuery("#new_foldername").length > 0){
jQuery("#new_foldername").focus(function() { jQuery(this).select(); } );
}
});
如果我在检查 #new_foldername 是否存在后发出警报,我会看到警报,并且会看到背景中突出显示的文本(因此我的突出显示文本的代码有效)。当我单击关闭警报时,表格完成排序...并且文本不再突出显示。
有什么想法可能会发生什么吗?
最佳答案
排序似乎是异步进行的。该文档提供了一个名为“sortEnd”的 Hook ,您可能想在其中运行突出显示代码。参见示例 http://tablesorter.com/docs/example-triggers.html
$(document).ready(function() {
// call the tablesorter plugin, the magic happens in the markup
$("table").tablesorter();
//assign the sortStart event
$("table").bind("sortStart",function() {
$("#overlay").show();
}).bind("sortEnd",function() {
$("#overlay").hide();
});
});
关于jQuery tablesorter 插件 - 在表排序后执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3301172/