google.maps.event.addListener和秋季通话

时间:2013-03-20 14:50:08

标签: javascript jquery google-maps-api-3 event-handling

我创建了这个标记,我想对标记进行附加和处理,当我点击标记时,我想在infowindow中显示一个对象:

var marker = new google.maps.Marker({
    position: posizione,
    map: map,
    title: "Title"
});

markerClick = function () {
    templateFinestra.find('.titolo').html("New Title");
    var prova = templateFinestra.find('.myLink');
    google.maps.event.addDomListener(prova, 'click', alert("Hello"));

    infoWindow.setContent(templateFinestra.html());
    infoWindow.open(map, marker);       
};

google.maps.event.addListener(marker, 'click', markerClick);

但是当我点击标记时,我会看到警报!为什么?我怎样才能创建2个单独的处理程序? (一个用于标记,一个用于在我点击标记时打开的infowindow链接。)

1 个答案:

答案 0 :(得分:1)

因为您正在立即执行它并将其作为函数返回(它不是)。

google.maps.event.addDomListener(prova, 'click', function(){
    alert("Hello")
});