我使用ASP.NET MVC 4 JavaScript方法,我有這樣一個DIV:DIV onload事件不觸發
<div id="map_canvas" style="width: 500px; height: 400px;" onload="mapAddress();"></div>
然後,在JavaScript文件(,我已經驗證加載)被mapAddress
功能:
function mapAddress() {
//In this case it gets the address from an element on the page, but obviously you could just pass it to the method instead
var address = $("#Address").val();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var myLatLng = results[0].geometry.location.LatLng;
var mapOptions = {
center: myLatLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: $("#Name").val() + " Location"
});
}
else {
alert("The location of the event could not be mapped because: " + status);
}
});
}
但是,無論什麼原因,它不被稱爲。我誤解了onload
事件嗎?
謝謝大家!
謝謝,這個工作就像一個魅力。對不起,我的無知!有時候你想知道,你已經做了十多年,並且仍然在這裏和那裏想念這樣的事情。只是證明我們並不完美。 –