我正在调用带有参数标记的函数fxn,但我无法在函数定义中检索其值(如 id),但我需要在该点击上打开一个信息窗口需要在按钮或 div 点击上打开信息窗口,这已经完成但有一个错误
$(document).ready(function() {
$.ajax({
type: "GET",
url: "empty/GovtEmp.aspx",
success: function(data) {
obj = JSON.parse(data);
var ary = data.split(",");
mycenter = new google.maps.LatLng(24.6510734558105, 46.7010765075684);
var mapOptions = {
center: mycenter,
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
for (i = 0; i < obj.POI.length; i++) {
var location = new google.maps.LatLng(obj.POI[i].Latitude, obj.POI[i].Longitude);
var marker = new google.maps.Marker({
position: location,
id: obj.POI[i].Poi_Id,
html: "dataaaaaaaaa",
map: map
});
infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function(event) {
po = 1;
$(".AdsDivLeft").css("color", "black");
$(".AdsDivLeft").css("background-color", "white");
$("#divLft" + this.id).css("color", "green");
$("#divLft" + this.id).css("background-color", "yellow");
infowindow.setContent(this.html);
infowindow.open(map, this);
});
google.maps.event.addListener(marker, 'mouseover', function(event) {
//$("#divLft" + POI[i].Poi_Id).css("color", "black");
po = 0;
$("#divLft" + this.id).css("color", "green");
$("#divLft" + this.id).css("background-color", "yellow");
infowindow.setContent(this.html);
infowindow.open(map, this);
});
google.maps.event.addListener(marker, 'mouseout', function(event) {
if (po == 0) {
$(".AdsDivLeft").css("color", "black");
$(".AdsDivLeft").css("background-color", "white");
infowindow.close(this.html);
}
});
divPan = document.createElement("div");
divPan.id = "divLft" + k;
divPan.className = "AdsDivLeft";
divPan.style.border = "groove 5px #FDFDFD";
divPan.innerHTML = "<div style=\"border:solid 2px red;\" onclick='fxn(\"" + marker + "\")'>Click</div>";
}
}
});
});
function fxn(mrkr) {
alert(mrkr.id);
infowindow = new google.maps.InfoWindow();
infowindow.setContent(mrkr.html);
infowindow.open(map, mrkr);
}