我使用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
事件吗?
谢谢大家!
谢谢,这个工作就像一个魅力。对不起,我的无知!有时候你想知道,你已经做了十多年,并且仍然在这里和那里想念这样的事情。只是证明我们并不完美。 –