'若'声明改变功能

时间:2013-04-17 12:23:31

标签: javascript variables if-statement

我正在尝试添加一个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'));

1 个答案:

答案 0 :(得分:1)

一定是

if (marker.name == 'chester')

if (marker.name = 'chester')