javascript google.maps.event.addDomListener(window, 'load', initialize); 的作用是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17742314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the function of google.maps.event.addDomListener(window, 'load', initialize);?
提问by Daniel Listyo Emanuel
I was trying Google maps. I found this statement.
我正在尝试谷歌地图。我找到了这个说法。
google.maps.event.addDomListener(window, 'load', initialize);
what is the function of that statement ?
该语句的功能是什么?
回答by deceze
It adds a listener to the window
object, which as soon as the load
event is triggered (i.e. "the page has finished loading") executes the function initialize
.
它向window
对象添加了一个侦听器,一旦load
触发事件(即“页面已完成加载”),它就会执行函数initialize
。
I.e. it delays the Google Map related script until the page has finished loading.
即它延迟谷歌地图相关的脚本,直到页面完成加载。
回答by Jagpat Singh
@Dust function is initialize and it is called only after the <div> element is loaded. in maps.event..., I think event is element because essentially it contains the map-canvas information.
@Dust 函数被初始化并且只有在 <div> 元素被加载后才会被调用。在 maps.event... 中,我认为 event 是元素,因为它本质上包含地图画布信息。