如何模拟追加回调函数? [英] How to simulate an append callback function?

查看:236
本文介绍了如何模拟追加回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 .append()没有任何回调函数,但是当我尝试这样做:

I know that .append() does not have any callback function, but when I try to do this:

$.onShadowboxFinished = function (f) {

var postid = $(f.link).parent().attr("id");
var loadUrl = "wp-admin/admin-ajax.php?action=mfields_show_post&p=" + postid;
$('#infos_wrap').load(loadUrl).append();
alert("loaded! test selector :"+$('a.projectimgs').first().attr("href"));

}

我加载内容(链接和图像)插入DIV #infos_wrap 。一旦所有链接和图像加载,我要处理的内容(例如:选择的链接,将它们添加到太极拳缓存)

I am loading content ( links and images ) into the div #infos_wrap. Once all links and images are loaded, I want to manipulate content ( example : Select the links to add them to the shadowbox cache )

目前,4号线是3TH之前执行的。

For now, the 4th line is executed before the 3th.

感谢您的帮助!

PS:如果有人真的要帮助(我AP preciate它^^)结果
您可以查看网站: http://www.tom-portfolio.fr/wp-login .PHP 结果
登录:游客结果
通过为访客结果
JavaScript文件的 portfolio.js 结果
用你的萤火或GoogleDev工具来查看吧!结果
非常感谢!

PS : If someone want really to help ( i'd appreciate it ^^ )
You can check the site : http://www.tom-portfolio.fr/wp-login.php
login: visitor
pass: visitor
The javascript file is portfolio.js
Use your firebug or GoogleDev tools to view it!
Thanks a lot !

推荐答案

您想要做的是使用回调函数的 .load()函数,因为它是异步(意为code它一直执行,直到它临危响应,并触发其回调函数后):

What you want to do is use the callback function for the .load() function because it is asynchronous (meaning the code after it keeps executing until it recieves a response and fires its callback function):

var postid  = $(f.link).parent()[0].id,
    loadUrl = "wp-admin/admin-ajax.php?action=mfields_show_post&p=" + postid;

$('#infos_wrap').load(loadUrl, function () {
    alert("loaded! test selector :"+$('a.projectimgs').first()[0].href);
});

注意 .load()将取代 #infos_wrap 与来自AJAX调用的响应内容( #infos_wrap 在这种情况下),所以我们不必使用 .append()(内部的.html()用于取代所选元素(S)的HTML,而不是附加的响应)。

Note that .load() will replace the contents of #infos_wrap with the response from the AJAX call (#infos_wrap in this case) so we don't have to use .append() (internally .html() is used which replaces the HTML of the selected element(s) rather than appending the response).

另外请注意,我改变了一对夫妇的实例.attr(),其中并不需要它。

Also note that I changed a couple instances of .attr() where it wasn't needed.

文档.load()的http:// api.jquery.com/load

这篇关于如何模拟追加回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆