3

クリックを待つイベントリスナーが必要です。残念ながら、それが機能した方法はInfoWindowsここでは機能しないようです...

さて、これが私のものInfoBubbleです:

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 によって報告されたエラーはありません。

4

4 に答える 4

6

これを試して:

$(infoBubble.bubble_).live("click", function() {
    console.log('clicked!');
});
于 2012-09-11T12:45:59.330 に答える
1
google.maps.event.addDomListener(infoBubble.bubble_, 'click', function() {
    alert("Ooo..!");
});

できます!

于 2012-12-28T18:21:02.413 に答える
1

@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.bubble_).on("click", ".my-style", function (e) {
    if ($(e.target).data('id')) {
        var myVariableValue = $(e.target).data('id'); // myVariableValue will equal 10
    }
});
于 2016-12-19T23:14:36.147 に答える