gpt4 book ai didi

javascript - 当Google Maps +其他库完全加载时调用函数?

转载 作者:行者123 更新时间:2023-12-03 04:33:49 27 4
gpt4 key购买 nike

我加载谷歌地图 API 并使用 callback 参数执行初始化函数 initMap() :

<script async="" defer="" src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxx&amp;callback=initMap"></script>

我想使用其他脚本 (js-rich-marker) 来创建自定义标记(具有 css 样式)。

我加载:

script async="" defer="" src="https://raw.githubusercontent.com/googlemaps/js-rich-marker/gh-pages/src/richmarker-compiled.js"></script>

但是 initMap(); 在页面加载时不起作用:

ReferenceError: Can't find variable: RichMarker

(我知道该脚本可以工作,因为我可以使用菜单更新 map ,该菜单使用 AJAX 更新 map ,在本例中它可以工作。)。

我猜这是因为 init 函数是在 js-rich-marker 完全加载之前执行的。

我尝试在所有内容加载完毕后调用 init 函数,但仍然不行。

document.addEventListener("DOMContentLoaded", function(event){
initMap();
});

$(window).load(function() {
initMap();
});

$(window).bind("load", function() {
// code goes here
});

如何在所有内容都加载后调用函数?

最佳答案

window.document.onload= function(e){

}
window.onload = function(e){

}

并调用下一个 js-rich-marker示例:

关于javascript - 当Google Maps +其他库完全加载时调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43380014/

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