Events 谷歌地图API-InfoBubble事件监听器不';行不通

Events 谷歌地图API-InfoBubble事件监听器不';行不通,events,google-maps-api-3,infobubble,Events,Google Maps Api 3,Infobubble,我需要一个事件侦听器等待单击。不幸的是,它在InfoWindows上的工作方式在这里似乎不起作用 这是我的信息泡泡: var infoBubble = new InfoBubble({ map: map, content: $('#my-div').html(), position: new google.maps.LatLng(areas[area].lat, areas[area].lng), shadowStyle: 1, pad

我需要一个事件侦听器等待单击。不幸的是,它在
InfoWindows
上的工作方式在这里似乎不起作用

这是我的
信息泡泡

var infoBubble = new InfoBubble({
      map: map,
      content: $('#my-div').html(),
      position: new google.maps.LatLng(areas[area].lat, areas[area].lng),
      shadowStyle: 1,
      padding: 0,
      borderRadius: 0,
      arrowSize: 10,
      borderWidth: 1,
      borderColor: '#ccc',
      disableAutoPan: true,
      hideCloseButton: true,
      arrowPosition: 15,
      arrowStyle: 0
    });
下面是我的听众:

google.maps.event.addListener(infoBubble, 'click', function(){

        console.log("noodle");  
    });
顺便说一句,Firebug没有报告任何错误。

试试这个:

$(infoBubble.bubble_).live("click", function() {
    console.log('clicked!');
});

它起作用了

如果您使用的是InfoBubble的编译版本,则.bubble_uu引用将丢失。你必须找到什么。泡泡已经变成了什么。 如果您还没有编译自己的,并且使用了提供的编译版本,.bubble\uu.引用是.e。 例如:

$(infoBubble.e).find("#yourdiv").live("click",function(event) {
    console.log(event.target.id);
});

要进一步改进@Marius的答案,并将其更新为jQuery的当前版本(因为我可以看到OP有可用的jQuery),请尝试以下操作,以针对infoBubble中特定元素的单击事件:

$(infoBubble.bubble_).on("click", "button.close", function() {
    console.log("Button with class .close clicked.");
});
如果需要将数据传递给函数,一个选项是使用data-*属性并通过事件目标获取数据,如下所示:

InfoBubble内容的示例JS:

var myVariable = 10;
var infoBubbleContentString = '<span class="my-style" data-id="' + myVariable + '">Button text</span>';
$(infoBubble.e).on(“单击”,函数(e){})
在live已贬值的jQuery版本中工作。
var myVariable = 10;
var infoBubbleContentString = '<span class="my-style" data-id="' + myVariable + '">Button text</span>';
$(infoBubble.bubble_).on("click", ".my-style", function (e) {
    if ($(e.target).data('id')) {
        var myVariableValue = $(e.target).data('id'); // myVariableValue will equal 10
    }
});