我正在使用Jquery加载,然后一旦内容加载到div中,我就从新的内容加载另一个内容。我的问题是“prec3”不会加载。我能怎么做?可能使用settimeout?
$(document).ready(function(){
var filtralink = $('.blockhead a').filter('a[href^="http://site.com/photo/showgallery.php?cat="]').attr('href').split(/=/)[1];
var primaimmagine = $('.forumrow table').find('img:first').attr('src').split(/medium/)[1];
var fotothumb = "http://site.com/photo/data/" + filtralink + "/thumbs" + primaimmagine;
fotothumbdarip =fotothumb;
$('body').prepend('<br /><div id="precunz" class="precunz" name="precunz"></div><div id="precduz" class="precduz" name="precduz"></div><div id="prectruz" class="prectruz" name="prectruz"></div>');
$('div[align=center]:eq(1)').append('<br /><ul id="categories"><li><a href="#load">load</a></li><div class="dropdown"><ul><li><a href="#show">Show</a></li></ul></div></ul><div id="precun" class="precun" name="precun"></div><div id="precdu" class="precdu" name="precdu"></div>');
$(".precunz,.precduz,.prectruz").hide();
var prec1 = $(".forumrow table").find('a').filter(':contains(previous)').attr('href');
prec1darip =prec1;
var prec1cat1split = $('.blockhead a').filter('a[href^="http://site.com/photo/showgallery.php?cat="]').attr('href').split(/=/)[1];
$(".precunz").load(prec1+" ol.floatcontainer");
$('#categories > div').hide();
var $listHeader = $('#categories > li');
$listHeader.live("click" ,function(event) {
event.preventDefault();
$('#categories > div').toggle();
var prec2 = $(".precunz .forumrow table").find('a').filter(':contains(previous)').attr('href');
prec2darip=prec2;
var prec2cat1split = $('.blockhead a').filter('a[href^="http://site.com/photo/showgallery.php?cat="]').attr('href').split(/=/)[1];
prec2cat1splitdarip = prec2cat1split;
var prec2immgran = $('.precunz .forumrow table').find('img:first').attr('src').split(/medium/)[1];
prec2immgrandarip = prec2immgran;
$(".precduz").load(prec2+" ol.floatcontainer");
/// This prec3 can't load
var prec3 = $(".precduz .forumrow table").find('a').filter(':contains(previous)').attr('href');
prec3darip=prec3;
var prec3cat1split = $('.blockhead a').filter('a[href^="http://site.com/photo/showgallery.php?cat="]').attr('href').split(/=/)[1];
prec3cat1splitdarip = prec3cat1split;
var prec3immgran = $('.precduz .forumrow table').find('img:first').attr('src').split(/medium/)[1];
prec3immgrandarip = prec3immgran;
$(".prectruz").load(prec3+" ol.floatcontainer");
});
$('#categories > div a').click(function() {
$('#categories > div').hide();
$(this).prependTo('#categories > li');
$('#categories > li > a:eq(1)').prependTo('#categories > div > ul > li:empty');
$listHeader = $('#categories > li');
var prec1immgran = $('.precunz .forumrow table').find('img:first').attr('src').split(/medium/)[1];
var prec1th = "http://site.com/photo/data/" + prec1cat1split + "/thumbs" + prec1immgran;
$('.precun').append('<a href="' +prec1+ '"><img src="' +prec1th+ '" alt="" />');
var prec2immgran = $('.precduz .forumrow table').find('img:first').attr('src').split(/medium/)[1];
prec2th = "http://site.com/photo/data/" + prec2cat1splitdarip + "/thumbs" + prec2immgran;
$('.precun').append('<a href="' +prec2darip+ '"><img src="' +prec2th+ '" alt="" /></a>');
/// this wont work because prec3 is not there
var prec3immgran = $('.prectruz .forumrow table').find('img:first').attr('src').split(/medium/)[1];
var prec3th = "http://site.com/photo/data/" + prec3cat1splitdarip + "/thumbs" + prec3immgran;
$('.precun').append('<a href="' +prec3darip+ '"><img src="' +prec3th+ '" alt="" /></a>');
$('.precun').append('<a href="' +$(location).attr('href')+ '"><img src="' +fotothumbdarip+ '" alt="" />');
return false;
});
});
答案 0 :(得分:0)
load()函数接受onComplete回调作为参数,因此如果需要延迟prec3加载直到prec2加载完成后,您可以这样做:
var prec2 = $(".precunz .forumrow table").find('a').filter(':contains(previous)').attr('href');
prec2darip=prec2;
var prec2cat1split = $('.blockhead a').filter('a[href^="http://site.com/photo/showgallery.php?cat="]').attr('href').split(/=/)[1];
prec2cat1splitdarip = prec2cat1split;
var prec2immgran = $('.precunz .forumrow table').find('img:first').attr('src').split(/medium/)[1];
prec2immgrandarip = prec2immgran;
$(".precduz").load(prec2+" ol.floatcontainer", function(){
var prec3 = $(".precduz .forumrow table").find('a').filter(':contains(previous)').attr('href');
prec3darip=prec3;
var prec3cat1split = $('.blockhead a').filter('a[href^="http://site.com/photo/showgallery.php?cat="]').attr('href').split(/=/)[1];
prec3cat1splitdarip = prec3cat1split;
var prec3immgran = $('.precduz .forumrow table').find('img:first').attr('src').split(/medium/)[1];
prec3immgrandarip = prec3immgran;
$(".prectruz").load(prec3+" ol.floatcontainer");
});