javascript - 如何在选项卡infobubble中添加id

标签 javascript google-maps google-maps-api-3

我需要您的帮助将事件 CLI 添加到选项卡 infobubble 中。此事件应通过单击选项卡选项卡 1 来显示警报。当我无法在选项卡上创建 id 时,问题就会出现

http://jsfiddle.net/hT8Kw/11/

map_initialize(); // load map
function map_initialize(){
    var mapOptions = {
      center: new google.maps.LatLng(37.286172, -121.80929),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        mapOptions);

    var myLatlng = new google.maps.LatLng(37.286172, -121.80929);
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'A Customized InfoWindow Marker'
    });

    var  infoBubble = new InfoBubble({
      maxWidth: 300
    });

    var div = document.createElement('DIV');
    div.innerHTML = 'Hello';

    infoBubble.addTab('Tab 1', div);
    infoBubble.addTab('Tab 2', "1234");

    //Add event clic into Tab 1. If click in Tab 1 show alert.

    google.maps.event.addListener(marker, 'click', function() {
      if (!infoBubble.isOpen()) {
        infoBubble.open(map, marker);
      }
    });
  }

最佳答案

我将 id 添加到选项卡 1,但单击事件不起作用。 请像这样编写选项卡 1。

infoBubble.addTab('<div onclick="myfunction();">Tab1</div>', div);

//tab 1 click event
function myfunction(){
 alert("Tab1");
}

关于javascript - 如何在选项卡infobubble中添加id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46250121/

相关文章:

javascript - 如何删除堆积柱形谷歌图表中的白色边框?

javascript - 提供的脚本使用 jQuery 的 $,但 drupal 站点没有启用冲突

javascript - 两个Web组件之间的绑定(bind): Google map + geo-localisation

google-maps - 错误: Google Maps API error: MissingKeyMapError

javascript - Laravel - 消息 Toastr,错误或无效输入字段

javascript - 如何在 Rails 中使用带有 anchor 的 Ajax 链接

ios - 自定义 Google map 样式在 iPad 上不起作用

javascript - 重新绘制谷歌地图以查看隐藏的移动标记

javascript - 谷歌地图不显示? Cordova 插件

javascript - Google map - 获取英国各县的坐标