0
以下函數可用,但我正在研究改進代碼。我想要做的第一件事就是刪除「myOption」對象中的樣式,以便之前加載它們,並且只保留內容,以便從AJAX調用中獲取數據。加入對象屬性
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
draggable: true,
position: results[0].geometry.location
});
var marker = new google.maps.Marker({
position: marker.position,
map: map,
title: results[0].formatted_address
});
$.ajax({
url: url+marker.position.ob+","+marker.position.pb+"",
dataType: "jsonp",
success: function (data) {
var myOptions = {
content: template(data)
,disableAutoPan: true
,maxWidth: 0
,pixelOffset: new google.maps.Size(-240, 0)
,zIndex: null
,boxStyle: {
background: "url('tipbox.gif') no-repeat"
,opacity: 0.9
,width: "454px"
}
,closeBoxMargin: "10px 10px 2px -20px"
,closeBoxURL: "assets/image/x.png"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
var ib = new InfoBox(myOptions);
ib.open(map, marker);
}
});
}
else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
我想創建一個樣式對象和AJAX調用之前加載它,並且比包含數據的對象加入它不是通過內單個對象的「新信息框(NewObject的)」
任何如何做到這一點的想法或者是否有不同的/更好的方式?