weixin_33725722 2011-10-07 02:39 采纳率: 0%
浏览 21

在Google Marker中检测事件

In my code, how can I get the name of the User that someone clicked on in the marker? Currently my code has:

 function createMarker(point, user, studytopic) {
      var marker = new GMarker(point);
      var currUser = user;
      var html = '<b>' + user + '</b> <br/>' + studytopic + '<br/>' +
      '<a href="javascript:showContactSB()"> Contact ' + user + '</a>' ;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

currUser is a global field, however, it's not updated every time I click on a different marker in Google maps. Basically what I'm looking for is a event to fire when a link (id=contactSBLink) within any marker is clicked. I want it to get the Username(which is a link) to pass the user variable to another function. I'm not sure what's the best way to go about to get this?

  • 写回答

1条回答 默认 最新

  • 游.程 2011-10-07 10:35
    关注

    You can pass the user u to the javascript:showContactSB(u). This is an exercise in setting quotes properly:

    var u = "'" + user + "'"; 
    var html = '<b>' + user + '</b> <br/>' + studytopic + '<br/>' +
        '<a href="javascript:showContactSB(' + u + ')"> Contact ' + user + '</a>' ;
    

    Now, you get the user in the click-function:

    function showContactSB(user) {
        alert("Hi " + user);
    }
    

    BTW, I would recommend you to upgrade to Google Maps v3.

    评论

报告相同问题?