Click event in Google Map InfoWindow not caught

前端 未结 6 1839
暖寄归人
暖寄归人 2021-02-08 13:43

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);

...

marke         


        
6条回答
  •  不知归路
    2021-02-08 14:28

    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.

    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);
    

提交回复
热议问题