谷歌地图:用jquery问题打开InfoWindow Html

时间:2010-01-29 20:25:15

标签: jquery google-maps

我添加了用户在我的Google地图上添加新点的功能。我的代码:

GEvent.addListener(map, "click", function(overlay,point) {
    if (point) {
        var myHtml = '<div id="addpoint"><form id="formadd" name="formadd_point" enctype="multipart/form-data" method="post" action="pointadd.php"><table><tr><td>Place:</td><td>' + point + '</td></tr><tr><td>Name:</td><td><input name="name" type="text" size="32" maxlength="200" /></td></tr><tr><td>Photo (jpg,png:2Mb):</td><td><input type="file" name="image" size="20" accept="image/png,image/jpeg" /></td></tr><tr><td></td><td><input name="pcoord" type="hidden" value="'+point+'" /><input type="hidden" name="MAX_FILE_SIZE" value="2000000" /><input name="subpoint" type="submit" value="Add" /></td></tr></table></form></div>';
        map.openInfoWindowHtml(point, myHtml);
        $('#formadd').ajaxForm({ beforeSubmit: validate, target:'#addpoint' });
    }
});

它应该是没有重新加载的AJAX帖子。但它不起作用!我不知道为什么。也许有一些冲突jquery.js和google api?如何在不重页的情况下提交表单?

1 个答案:

答案 0 :(得分:1)

也许你尝试在表单html成功添加dom之前将eventListener添加到表单中。试试这个:

GEvent.addListener(map, "click", function(overlay,point) {
    if (point) {
        $('#formadd').live("load", function(){
            $(this).ajaxForm({ beforeSubmit: validate, target:'#addpoint' });
        });

        var myHtml = '<div id="addpoint"><form id="formadd" name="formadd_point" enctype="multipart/form-data" method="post" action="pointadd.php"><table><tr><td>Place:</td><td>' + point + '</td></tr><tr><td>Name:</td><td><input name="name" type="text" size="32" maxlength="200" /></td></tr><tr><td>Photo (jpg,png:2Mb):</td><td><input type="file" name="image" size="20" accept="image/png,image/jpeg" /></td></tr><tr><td></td><td><input name="pcoord" type="hidden" value="'+point+'" /><input type="hidden" name="MAX_FILE_SIZE" value="2000000" /><input name="subpoint" type="submit" value="Add" /></td></tr></table></form></div>';
        map.openInfoWindowHtml(point, myHtml);

    }
});