我想添加一個If語句來更改一個特定點的函數的參數,但代碼似乎將第一個函數應用於所有點,而不管if語句。'如果'語句來更改函數
下面的代碼創建一個新的標記,然後根據if語句執行函數 - 至少它應該!
我在做什麼錯?
function createMarker(point, name, file_name) {
var blueIcon = new GIcon(G_DEFAULT_ICON);
blueIcon.image = "images/mark22.png";
blueIcon.iconSize = new GSize(32, 32);
markerOptions = { icon: blueIcon };
var marker = new GMarker(point, markerOptions);
GEvent.addListener(marker, "click", function() {
if (marker.name = 'chester') {
marker.openInfoWindowHtml("<a class='text1' href='http://www.merseyrail.org/plan-your-journey/stations/" + file_name + ".aspx' target='_parent'>" + name + " Station</a><br /><font size='2' face='Arial'><i>Click the station name to view more information.</i></font>");
}
else {
marker.openInfoWindowHtml("<img src='images/merseyraillogosmall.png'/><br /><a class='text1' href='http://www.merseyrail.org/plan-your-journey/stations/" + file_name + ".aspx' target='_parent'>" + name + " Station</a><br /><font size='2' face='Arial'><i>Click the station name to view more information.</i></font>");
}
});
return marker;
}
,然後進一步下跌:
var point20 = new GLatLng(53.1968, -2.88018);
map.addOverlay(createMarker(point20, 'Chester'));
試試看'如果(marker.name =='切斯特) ':) – sinsedrix
你有沒有設置標記的名稱屬性(marker.name = nam e)? – Andre
@Andre不,我沒有,現在完美的工作,謝謝!不能相信我錯過了! – user1595799