嘿伙计们,我想为地图上的每个标记创建一个带有信息窗口的 onclickEvent。在那个信息窗口中应该有一个按钮。如果我单击按钮,则应执行带有参数的函数。但这不起作用...
我的代码:
var infowindow;
google.maps.event.addListener(marker,"click",function() {
var content="<input type='button' name='Edit' value='Edit' onclick='"+editPreference(preference)+"' id='NearbyEditButton"+counterNearby+"'>"
+ "<input type='button' name='Delete' value='Delete' onclick='deleteMarker(\"preference\")' id='NearbyDeleteButton"+counterNearby+"'>"
+ "<br>"
+ "</form>";
infowindow = new google.maps.InfoWindow();
infowindow.setContent(content);
infowindow.open(map, marker);
这是偏好对象
var preference = {
type : "NEARBY",
marker : marker,
position : latLng,
dPar : 10,
cPar : 10,
measureFn : "Euklidische Distanz",
label : "Nearby" + counterNearby,
id : "nearby" + counterNearby,
deleteButton: "NearbyButton"+counterNearby,
editButton: "EditButton"+counterNearby
};
这是使用首选项参数执行的函数
function editPreference(preference) {
alert(preference.type);
deleteFromArray(preferences, preference);
if (!isNaN(document.getElementById("dPar").value)) {
preference.dPar = document.getElementById("dPar").value;
} else {
alert("Please enter a number for d-Paramater");
}
if (!isNaN(document.getElementById("cPar").value)) {
preference.cPar = document.getElementById("cPar").value;
} else {
alert("Please enter a number for c-Paramater");
}
preference.label = document.getElementById("Lab").value;
var d = document.getElementById("dist");
var d1 = d.options[d.selectedIndex].text;
preference.measureFn = d1;
alert(d1);
preferences.push(preference);
}