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