gpt4 book ai didi

javascript - 如何监听两个加载事件?

转载 作者:行者123 更新时间:2023-12-02 18:36:54 25 4
gpt4 key购买 nike

如何同时监听这些事件? (目前无法使用)

<!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>

最佳答案

从 body 标记中删除“onLoad”并将其添加到脚本中,如下所示:-

window.addEventListener("load", onLoad);

这样您就可以监听加载事件上添加的多个事件。

您可以查看此内容以更好地理解

element.onload vs element.addEventListener("load",callbak,false)

关于javascript - 如何监听两个加载事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17236597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com