Google Map InfoWindow中的点击事件没有被捕获 [英] Click event in Google Map InfoWindow not caught

查看:127
本文介绍了Google Map InfoWindow中的点击事件没有被捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google Map v2,我希望能够在单击GMarker的InfoWindow中的文本时触发一个函数。

With Google Map v2, I would like to be able to trigger a function when clicking a text in the InfoWindow of a GMarker.

$(".foo").click(myFunction);

...

marker.openInfoWindowHtml("<span class=\"foo\">myText</span>");

不起作用。为什么事件没有被捕获到InfoWindow中?

does not work. Why the event isn't caught inside the InfoWindow ?

推荐答案

如果在调用openInfoWindowHtml之前调用事件绑定调用,在你的例子中,跨度不在DOM中,而第一次调用寻找类foo的元素,所以没有处理程序被附加。

If the event binding call is called before the call to openInfoWindowHtml as it is in your example, the span wasn't in the DOM while the first call was looking for elements with the class "foo," so no handler was attached.

你可以移动该事件处理程序以在openInfoWindowHtml之后调用,或者使用实时事件绑定,以便jQuery将使用给定的选择器监视DOM的任何新元素。

You can either move that event handler to be called after openInfoWindowHtml, or use "live" event binding so that jQuery will monitor the DOM for any new elements with the given selector.

$(".foo").live('click', myFunction);

这篇关于Google Map InfoWindow中的点击事件没有被捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆