jqueryajax问题
如果你看 我编写了以下函数,以每五行添加一个表头:jqueryajax问题,jquery,ajax,Jquery,Ajax,如果你看 我编写了以下函数,以每五行添加一个表头: jQuery.fn.hrReplace = function() { var headers = $(this).find('table.products tr:eq(0)'); $(this).find('table.products tr:nth-child(5n)').after(headers); $(this).find('table.products tr:eq(0)').before(headers);
jQuery.fn.hrReplace = function() {
var headers = $(this).find('table.products tr:eq(0)');
$(this).find('table.products tr:nth-child(5n)').after(headers);
$(this).find('table.products tr:eq(0)').before(headers);
}
这在加载页面时效果很好。然后,我在ajax命令中添加了该函数:
$.ajax({
type: "POST",
url: formAction,
data: myForm,
success: function() {
$('#top_bar').load(base + 'index.php #top_bar');
$('#' + divId).load(document.URL + '&random=' + Math.random() * 99999 + ' #' + divId, {
'gaugeMinFil':parseFloat($('input[name="gaugeLow"]').val()),
'gaugeMaxFil':parseFloat($('input[name="gaugeHigh"]').val()),
'lengthMinFil':parseFloat($('input[name="lengthLow"]').val()),
'lengthMaxFil':parseFloat($('input[name="lengthHigh"]').val())
});
$('#tableHolder').hrReplace();
}
});
但是在重新加载div hrReplace()之后,它就不起作用了。函数调用需要在.load调用的回调中,因此它会在完成后发生
$.ajax({
type: "POST",
url: formAction,
data: myForm,
success: function() {
$('#top_bar').load(base + 'index.php #top_bar');
$('#' + divId).load(document.URL + '&random=' + Math.random() * 99999 + ' #' + divId,
{
'gaugeMinFil':parseFloat($('input[name="gaugeLow"]').val()),
'gaugeMaxFil':parseFloat($('input[name="gaugeHigh"]').val()),
'lengthMinFil':parseFloat($('input[name="lengthLow"]').val()),
'lengthMaxFil':parseFloat($('input[name="lengthHigh"]').val())
},
function() {
$('#tableHolder').hrReplace();
}
);
}
});
问题是什么?另外,请在“不工作”处提供更多详细信息对不起,hrReplace函数从表中获取标题行,并在表中每隔五行插入一行。完成表的AJAX重新加载后,函数不再每隔五行插入标题行。
headers
参数从何而来?@bland_dan Great。。很高兴我能帮忙。