2016-05-17 40 views
-4

解决的事情真的很快我必须做以下逻辑用的setTimeout继续在JavaScript

function ajax(){ 

    setTimeout(function(){ 
     $('#something').click(function(){ 
      //how to continue here? 
     }); 
    },300); 

//api function here 
} 

有什么调用继续在JavaScript?我想要的是等待点击发生然后才进行。

+1

做出了榜样小提琴,因为目前还不清楚你问 – maioman

+0

继续什么,为什么?目前还不清楚你的目标是什么 – Liam

回答

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

function 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); 

}