1
是否有任何其他方式可以防止setTimeout
被需要?避免在ajax回調函數中設置setTimeout
function initialize(){
$.get('test.xml', function(xml){
//do some stuff with xml like...
var icons = xml.documentElement.getElementsByTagName("icon");
for(var i = 0; i < icons.length; i++) {
var iconImage = icons[i].getAttribute("image"),
}
//do more things to create markers like...
markers.push(marker);
//try to add markers to map
//this will give an error
addMarkers(markers);
//setTimeout makes it work
setTimeout("addMarkers(markers)", 300);
//is there any way to avoid the timeout?
});
}
它給了什麼錯誤? `marker`從哪裏來? – 2010-11-30 14:06:56