如何在javascript中按顺序激活3个不同的函数?
我已经试了一段时间了,但是我不能让它工作。 我的问题是:我有3个功能(1个使a div变小,1个更新div,1个放大div),这些功能由鼠标点击激活。但它们同时激活,这意味着第1个(使div变小)由于第2个(续订div)而被跳过。 第二个函数调用一个php函数来重新加载div中的数据。 以下是三个功能:如何在javascript中按顺序激活3个不同的函数?,javascript,jquery,html,Javascript,Jquery,Html,我已经试了一段时间了,但是我不能让它工作。 我的问题是:我有3个功能(1个使a div变小,1个更新div,1个放大div),这些功能由鼠标点击激活。但它们同时激活,这意味着第1个(使div变小)由于第2个(续订div)而被跳过。 第二个函数调用一个php函数来重新加载div中的数据。 以下是三个功能: function reduceView(Parent){ $(Parent).find('#details').hide("slow", function(){ // A
function reduceView(Parent){
$(Parent).find('#details').hide("slow", function(){
// Animation complete.
});
// get width and Extend
$(Parent).find("#" + Parent.ID + "").width("250px");
var width = $(Parent).find("#" + Parent.ID + "").css("width");
$(Parent).animate({
width: width
}, 500, function(){
// Animation complete.
});
}
function renewWindow(Parent){
$(":animated").promise().done(function(){
PHP.execute(Parent.id + "/home");
$(Parent).find("div[class='Item-list']").remove();
$(Parent).find("div[id='details']").remove();
$(Parent).find("div[id='confirmDialog']").remove();
$(Parent).append(PHP.response);
initJquery();
initEvents();
});
}
function enlargeView(Parent){
$(Parent).promise().done(function(){
$(Parent).find('#details').show("slow", function(){
// Animation complete.
});
// get width and Extend
$(Parent).find("#" + Parent.ID + "").width("683px");
var width = $(Parent).find("#" + Parent.ID + "").css("width");
$(Parent).animate({
width: width
}, 500, function(){
// Animation complete.
});
});
}
有什么线索可以让这3个正常工作吗?
“initJquery”和“initEvents”确保.click等都已重新初始化。
提前谢谢
另外,如果我遗漏了你可能需要的任何信息,请不要犹豫
编辑:下面是调用函数的代码
$(".selecter").click(function() {
var Element = this;
var ID = Element.id;
var Parent = $(Element).closest(".drag-div")[0];
reduceView(Parent);
renewWindow(Parent);
$(":animated").promise().done(function(){
PHP.execute(Parent.id + "/details?" + Parent.id + "id="+ID);
$(Parent).find('#details').html(PHP.response);
enlargeView(Parent);
initJquery();
});
$(Element).addClass("selected");
});
看起来您正在应用多个动画,然后使用$(“:animated”)选择器获得所需动画的承诺。您的答案中没有足够的代码来运行它,但我猜renewWindow中的关闭是由错误的promise对象触发的,可能是页面上与此功能无关的对象 尝试从第一个函数返回要设置关键帧的promise对象,如下所示:
function reduceView(Parent){
var promise = $(Parent).find('#details').hide("slow", function(){
// Animation complete.
}).promise();
// get width and Extend
$(Parent).find("#" + Parent.ID + "").width("250px");
var width = $(Parent).find("#" + Parent.ID + "").css("width");
$(Parent).animate({
width: width
}, 500, function(){
// Animation complete.
});
return promise;
}
然后,RenewalWindow可以使用该承诺:
function renewWindow(Parent, promise){
promise.done(function(){
PHP.execute(Parent.id + "/home");
$(Parent).find("div[class='Item-list']").remove();
$(Parent).find("div[id='details']").remove();
$(Parent).find("div[id='confirmDialog']").remove();
$(Parent).append(PHP.response);
initJquery();
initEvents();
});
}
这样,您就知道触发函数的承诺是用来隐藏div的承诺。您可以显示激活函数的post代码吗?Javascript函数应该按照调用它们的顺序执行。函数不是并发执行的。您应该在前面的函数的完成回调中调用下一个后续函数。谢谢!通过一次回访和承诺,我已经成功了!:D