信息窗口上的自定义按钮(如模态引导按钮)

Custom button on infowindws (like modal Bootstrap button)

本文关键字:按钮 模态 信息 窗口 自定义 信息窗      更新时间:2023-09-26

我有一个应用程序,当在一个信息窗口内,出现一个按钮"更多信息",打开一个模态视图。代码是:

(function(marker, data) {// Attaching a click event to the current marker
     google.maps.event.addListener(marker, "click", function() {
         geocoder.geocode({'latLng': marker.position}, function(results, status) {
           if(status == google.maps.GeocoderStatus.OK) {
              if (results[0]) { //defino la direccion
                 address = results[0].formatted_address;
                 info = '<h4>' + marker.title + '</h4><h4>'+ address+'</h4>';
                 var content = document.createElement('div'),button;
                 content.innerHTML = info + '<br/>';
                 button = content.appendChild(document.createElement('input'));
                 button.type = 'button';
                 button.value = 'More info';
                     google.maps.event.addDomListener(button, 'click', function () {
                        offsetCenter(marker,data);
                      })
                  infoWindow.setContent(content);

我的问题是关于按钮的样式。我如何添加按钮样式像模态引导按钮(即btn-primary类按钮)?

我找到了使用setAttribute属性的简单解决方案。只是用:

 button.setAttribute('class', 'btn btn-info');

我得到了信息窗口上的引导按钮。你可以为另一个类修改btn-info。

希望能有所帮助。