jQuery.load()回调函数完成之前运行

我正在使用jQuery的.load()来替换我的页面上的div与来自php文件的表格。我使用回调函数来运行另一个函数,该函数修改刚刚加载的数据,但是它在加载表之前正在运行该函数,导致该函数无法执行任何操作。
有没有办法强制加载后运行回调?我使用.load()每10秒运行一次,所以我不能让它等待。jQuery.load()回调函数完成之前运行

这里是我想要做的事:

function fixSelected(){ 

$.each(selected, function(index, value) {

document.getElementById(value).innerHTML = '-';

});

}

function refreshTable() {

$('#tablefill').load('table.php', function(){

fixSelected();

});

}

变量selected是含有正被装载在桌子上的几个按钮的ID的数组。

回答:

我有一个$(document).ready(function() {在table.php导致回调函数只是不工作。不知道为什么发生这种情况,但删除它解决了这一切。

回答:

您需要通过回调函数的load()函数的这样的第三个参数:

function fixSelected(){ 

$.each(selected, function(index, value) {

document.getElementById(value).innerHTML = '-';

});

}

function refreshTable() {

$('#tablefill').load('table.php', fixSelected);

}

我发现这里的解决方案:
jQuery.load() doesn't work with a defined function as a callback?

看到这个的jsfiddle为例:
http://jsfiddle.net/bayoffire/kNWpD/1/

以上是 jQuery.load()回调函数完成之前运行 的全部内容, 来源链接: utcz.com/qa/263503.html

回到顶部