在jQuery中的动态加载页面上执行自定义功能 [英] Execute custom function on dynamic loaded page in jQuery
问题描述
我在网页中有一个标签,使用此代码可以动态加载并显示另一个页面:
I have tab in a web page that loads and displays another page dynamically, using this code:
$(document).ready(function(){
$(".tab-content").hide();
$("#one").show();
$("a.tab-name").click(function(){
$(".tab-name-active").removeClass("tab-name-active");
$(this).addClass("tab-name-active");
$(".tab-content").fadeOut();
var content_show=$(this).attr("title");
if (content_show === 'three') {
$("#"+content_show).load('new-page.php');
}
$("#"+content_show).delay(100).fadeIn('slow');
return false;
});
});
现在,在第一页中,我有以下代码,该代码应使第二页的表可排序,该页是动态加载的:
Now, in the initial page I have this code, that should make sortable a table form the second page, the one loaded dynamically:
$(document).ready(function(){
$("#sorttable").tablesorter({
headers: {0: {sorter: false}}
});
});
唯一的问题是排序不起作用.我该如何运作?我认为这与live()
函数有关,但是我无法使其起作用.
感谢您的帮助.
The only problem is that the sort is not working. How can I make it work? I assume that is has something to do with the live()
function, but I'm not able to make it work.
Any help is appreciated.
谢谢!
推荐答案
您可以在 .load()
回调,如下所示:
You can run the code again in the .load()
callback, like this:
$("#"+content_show).load('new-page.php', function() {
$("#sorttable").tablesorter({
headers: {0: {sorter: false}}
});
});
加载内容后,它将再次执行.tablesorter()
插件.
This will execute the .tablesorter()
plugin again once the content is loaded.
这篇关于在jQuery中的动态加载页面上执行自定义功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!