谷歌地图(V3) - 地图容器选择器(使用jQuery) [英] Google maps (V3) - Map container selector (using jquery)
本文介绍了谷歌地图(V3) - 地图容器选择器(使用jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Google Maps(api V3)中解决一个棘手的问题。
很好用:
var map = new google.maps.Map(document.getElementById(map_container),myOptions);
如果我尝试使用jQuery选择器不起作用
var map = new google.maps.Map($('#map_container'),myOptions);
预先感谢您
干杯
Pedro
解决方案
元素,但 $('#map_container')
返回一个jQuery对象。如果您想使用jQuery选择器,请执行以下操作:
var map = new google.maps.Map($('#map_container ')[0],myOptions);
或者您也可以使用 .get(0)
而不是 [0]
,这将返回实际的DOM对象。
I'm trying to solve a tricky problem in Google Maps (api V3)
Works nicely:
var map = new google.maps.Map(document.getElementById("map_container"), myOptions);
Doesn't Work if I try to use a jQuery selector
var map = new google.maps.Map($('#map_container'), myOptions);
Thank you in advance
Cheers
Pedro
解决方案
It expects a DOM element, but $('#map_container')
returns a jQuery object. If you want to use a jQuery selector, do:
var map = new google.maps.Map($('#map_container')[0], myOptions);
Or you can also use .get(0)
instead of [0]
, this returns the actual DOM object.
这篇关于谷歌地图(V3) - 地图容器选择器(使用jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文