回调.trigger功能 [英] callback for .trigger function
问题描述
我有以下的code:
$("#scheduleLink").trigger("click");
alert("text")
这是单击处理程序:
$("#scheduleLink").bind("click", (function () {
loadScheduleEvent();
$(".wrap_tabs").find("a").removeClass("active");
$(this).addClass("active");
}));
和 loadScheduleEvent
功能:
function loadScheduleEvent() {
var eventId = $(".movie").attr("eventId");
var type = $(".movie").attr("type");
$("#publicationBlockContent").load("/Publication/EventSchedule?eventId=" + eventId + "&type=" + type);
}
我想,这code工作异步。我想,只有当 loadScheduleEvent
完成警报(文本)
调用。我怎样才能做到这一点?
I suppose that this code work async. I want that alert("text")
calls only when loadScheduleEvent
is finished. How can I do this?
感谢。
更新:
事实上,而不是警报(文本)
有一些code。而且,我不能动这个code回调 $的。负载
的功能。
UPDATE:
In fact, instead of alert("text")
there is some code. And, I can't move this code to callback of $.load
function.
推荐答案
如果你不想动了code。通过警报交替更换所有你能做的就是火一个事件,这将触发你的行为被警告取代。
If you don't want move that code replaced by alert alternatively all you can do is fire one event which triggers your behavior replaced by alert.
$("#scheduleLink").bind("click", (function () {
loadScheduleEvent();
$(".wrap_tabs").find("a").removeClass("active");
$(this).addClass("active");
}));
$(window).bind("scheduleComplete", (function (event,params) {
alert(params);
}));
现在在loadScheduleEvent你必须触发它。
Now in loadScheduleEvent you have to trigger it.
function loadScheduleEvent() {
var eventId = $(".movie").attr("eventId");
var type = $(".movie").attr("type");
$("#publicationBlockContent").load("/Publication/EventSchedule?eventId=" + eventId + "&type=" + type,function(){$(window).trigger("scheduleComplete");});
}
而在去年的时候,你这是什么顺序执行的,你只需要点击触发事件
And at last when you what this sequence execute you have to trigger only click event
$("#scheduleLink").trigger("click");
另外,如果你不想scheduleComplete事件被曝光窗口,你可以用你scheduleLink结合也并得到该行为范围和具体!!! ...
Also if you dont want scheduleComplete event to be exposed for window you can bind it with your scheduleLink also and get that behavior scoped and specific!!!...
这篇关于回调.trigger功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!