【发布时间】:2015-10-08 06:29:06
【问题描述】:
我的谷歌地图中有一堆带有信息窗口的标记。
最初,我将内容设置为带有<input type="text" ...> 和提交按钮的内容。在提交按钮的onclick="return submitForm();" 上,我调用了一个函数,该函数应该更改它所做的信息窗口的内容。但是当我关闭信息窗口并再次打开它时,文本正在被重置。我怎样才能让它留下来?
infowindow.setContent("This HTML content is being reset after reopening the infowindow");
infowindow.open(map, marker);
非常感谢!
_
编辑:
初始化:
function addCoordinate(lat, lon, text){
var marker = new google.maps.Marker({
position: (new google.maps.LatLng(lat, lon)),
title: '#' + path.getLength(),
map: map,
icon: image3
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<input type="text" id="wpname" value="'+ name +'" style="width:200px"><input type="hidden" id="wplat" value="'+ lat +'"><input type="hidden" id="wplon" value="'+ lon +'"><input type="submit" value="OK" onclick="return submitForm();"><br>'+ text +'<br><a href="javascript:removeCoordinate('+lat+', '+lon+');">Remove</a>');
infowindow.open(marker.get('map'), marker);
});
}
要调用的函数:
function submitForm() {
infowindow.setContent("This HTML content is being reset after reopening the infowindow");
infowindow.open(map, marker);
}
每当我单击提交按钮时,内容应从表单更改为“此 HTML 内容正在重置 [...]”。当我关闭信息窗口并再次打开它时,应该仍然有消息“此 HTML 内容正在重置 [...]”。
现在它被设置回带有提交按钮的表单。
【问题讨论】:
-
“正在重置文本”是什么?需要有关错误状态的更多详细信息。
-
初始化时到原文:google.maps.event.addListener(marker, 'click', function() { infowindow.setContent('original text'); infowindow.open(marker.get ('地图'), 标记); });
-
发布重现您遇到的问题的代码的最小版本。你如何加载你的标记,等等。我们不知道,所以很难提供帮助。在此处阅读更多信息:How do I ask a good question?。
-
好的,见编辑。提前致谢!
标签: javascript google-maps google-maps-api-3 infowindow