2013-04-08 27 views
0

我在我的网站上使用Google地图。将HTML追加到最初未加载的元素

现在,当在网站上显示地图时,可以点击不同的引脚(位置)。

一旦你点击一个位置,它会显示一个弹出框(谷歌地图气泡)。现在我想要在地址字段旁边添加其他内容,并且唯一的方法是使用jQuery。

这里是弹出泡的HTML:

<div class="google-map-placeholder"> 
<div class="bubble-content"> 
    <h4>Address: </h4> 
    <p class="custom-bubble-text">Lat and long...</p> 
    <p class="custom-bubble-text">PE Offices</p> 
</div> 
</div> 

我想怎么加我的自定义文本的自定义的地址:元素

的jQuery:

var x = $('div.google-map-placeholder').find('div.bubble-content p.custom-bubble-text').html(); 
      if(x == 'NY Offices'){ 
       $('div.google-map-placeholder').find('div.bubble-content h4').html('Address: My custom address'); 
      } 

,但它确实不工作(不追加我的HTML)...

我想我需要添加一个事件侦听器时点击地图标记图标,但我该怎么做?

google maps image

+0

你应该添加一个谷歌地图事件监听器:https://developers.google.com/maps/documentation/javascript/events?hl=fr – 2013-04-08 12:11:28

回答

1

http://api.jquery.com/click/

会让你添加一个事件监听器由一个jQuery对象表示一个DOM节点。

$("#target").click(function() { 
    alert("Handler for .click() called."); 
}); 

我觉得你可能会遇到与DOM是你的目标(弹出窗口内)的时候连的onClick触发没有准备好为你的onClick处理程序内修改的问题。