为了解决问题,我必须在逻辑
之下做function ajax(){
setTimeout(function(){
$('#something').click(function(){
//how to continue here?
});
},300);
//api function here
}
javascript中有什么呼叫继续吗?我想要的是等待点击发生然后才进行。
答案 0 :(得分:1)
我想你可以在这里使用一个标志:
function ajax(allowed){
if(!allowed){ return false; }
//api function here
}
现在称之为:
$('#something').click(function(){
//how to continue here?
ajax(false);
});
如果您希望用户确认要继续的操作,也可以使用此选项:
function ajax(){
if(confirm('Do you want to continue?')){ // prompts user to allow/disallow
//api function here
}
}
$('#something').click(function(){
//how to continue here?
ajax();
});
答案 1 :(得分:1)
函数ajax(){
$('#something').click(function(){
//you received button click event & your magic goes here & may b call your api whatever
});
setTimeout(function(){
//you cause button click event
$('#something').click();
},300);
}