2016-05-17 39 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); 

}