Infowindow与按钮

时间:2012-09-26 07:26:10

标签: google-maps-api-3 infowindow

嗨iam试图将按钮放在infowindow中,当我点击按钮时,某些动作应该至少发出警告。下面是我的代码

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    function initialize() {

        var mapOptions = {
            zoom: 7,
            center: new google.maps.LatLng(12.98,77.59),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById('map'), mapOptions);

        var infoWindow = new google.maps.InfoWindow();

        (function() {
            var marker = new google.maps.Marker({
                map: map,
                draggable: false,
                position: new google.maps.LatLng(12.98,77.59)
            });
            var content =   "<div id='tabs'>"+
                            "<form id='button'>"+
                            "<div>"+
                            "<input type='button' onclick='alert(infoWindow)'>"+
                            "</div>"+
                            "</form>"+
                            "</div>";  
   google.maps.event.addListener(marker, 'click', function(event) {
                infoWindow.setContent(content);
                infoWindow.open(map, marker);
            });
        })();

    };
  </script>
  </head>
  <body onload="initialize()">
    <div id="map" style="width:400px; height:300px"></div>
  </body>
  </html>

在这里我可以添加按钮,但无法使其工作..任何帮助将不胜感激

2 个答案:

答案 0 :(得分:2)

您将alert()中的值作为变量而不是字符串传递。您需要在单引号或双引号中传递此内容

var content =   "<div id='tabs'>"+
                "<form id='button'>"+
                "<div>"+
                "<input type='button' onclick='alert(\"infoWindow\")'>"+ // here
                "</div>"+
                "</form>"+
                "</div>";  

现在试试这个。

答案 1 :(得分:0)

如果您希望从InfoWindows中获取更多信息并将HTML内容放入其中,我建议您尝试使用InfoBox。查看参考here

它还有一些额外的功能,例如关闭窗口内置。

相关问题