谷歌地图API信息窗口-我可以从每个窗口提交表格



我有一个小的谷歌地图应用程序,可以用信息窗口绘制标记。我希望能够在窗口中编辑信息并提交。我可以这样做,但只能做一次。我在谷歌地图API信息窗口中将事件添加到元素中,这有点帮助,但使用我的代码,提交事件似乎不会触发。

这是我的代码:

// get the data       
    $.getJSON( 'csvToJson.php', function(data) { 
      // Loop through it
      $.each( data, function(i, m) {        
        // Add the marker
        var title = m.Namn + ': ' + m.Meddelande;
        $('#map_canvas').gmap('addMarker', { 
          'position': new google.maps.LatLng(m.Lat, m.Lng), 
          'bounds':false, 
          'title': title } 
          ).click(function() {
            // Initialise the info window
            var divName = "detail" + m.id; // come back to this?
            var infoWindowContent = [
              "<form id='detail_form' action='bib.php' method='post'>",
              "Namn: <br><input type='text' name='Namn' value='" + m.Namn + "'></input>",
              "<br>Meddelande: <br>"  + m.Meddelande,
              "<br><input type='submit' value='Spara ändringar'></input></form>"
             ].join("");
            var info = new google.maps.InfoWindow({
              content: infoWindowContent
            });                    
            google.maps.event.addListener(info, 'domready', function() {
              $(document).off("submit");
              $(document).on("submit", (function() {
                console.log("Hi");
              })); // end addEvent
            }); // end addListener 
            $('#map_canvas').gmap('openInfoWindow', info, this);                 
        }); // end addMarker click(function)     
      }); // end $.each
    }); // end $.getJSON

感谢所有的帮助。

迷你

  1. 没有jQuery方法addEvent,请改用on
  2. 在添加domready处理程序之前打开infoWindow,因此在应用侦听器时可能已经触发了domready事件。移动线路:

    $('#map_cnvas').gmap('openInfoWindow',info,this)

到点击监听器的末尾

最新更新