我怎样才能同时收听这些事件? (目前无效)
<!DOCTYPE html>
<html>
<head>
<title>Cordova Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
loadMap();
}
function loadMap() {
var map, layer;
function initialize() {
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: chicago,
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
layer = new google.maps.FusionTablesLayer({
query: {
select: '\'Geocodable address\'',
from: '1mZ53Z70NsChnBMm-qEYmSDOvLXgrreLTkQUvvg'
}
});
layer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
}
</script>
</head>
<body onload="onLoad()">
<div id="map-canvas"></div>
</body>
</html>
答案 0 :(得分:2)
从body标签中删除“onLoad”并在脚本中添加如下: -
window.addEventListener("load", onLoad);
这样您就可以收听加载事件中添加的多个事件。
您可以查看此内容以便更好地理解
element.onload vs element.addEventListener("load",callbak,false)