嗨,我使用下面的代碼。我需要一些方法讓腳本在運行initialize()之前等待clickButton()完成。或者等到推完成?任何幫助,將不勝感激。謝謝等到'for循環'或'推'完成然後運行功能 - Javascript
$("#getButtonValue").click(clickButton);
function clickButton() {
for(i = 1; i < counter; i++){
var geocoder = new google.maps.Geocoder();
var address = $('#textbox' + i).val()
geocoder.geocode({ 'address': address}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latCoords.push(results[0].geometry.location.lat());
longCoords.push(results[0].geometry.location.lng());
}
});
}
initialize();
}
Geocoder.geocode是一個承諾? –
我對JavaScript並不熟悉。我只是試圖鏈接兩個單獨的功能。我需要一個人等待另一個,我不知道如何去做。 – Munnaz
初始化是否被提前調用? –