2011-01-12 61 views
0

http://geodit.com:8000/test如何使用javascript模拟鼠标点击(在Google地图中)?

在这里,我有一个简单的Google本地搜索API和Google地图代码。

我该如何做到这一点,以便当我点击搜索结果的标题时,我模拟点击地址?我的目标是通过单击标题使弹出框出现在地图上。我绑定到这:

$(".gs-title").click(function(){ 

    //SIMULATE MOUSE CLICK of the address HERE 
    $(this).parent().parent().find(".gs-address").click(); // this doesn't work!! 

    alert("the title was clicked!!"); //this works fine. 
    return false; //this also works fine. The hyperlink gets disabled because I returned false. 

}); 

我希望能够点击标题,而不是打开链接。然后,弹出地图上的框。换句话说,我想把整个结果看待。

+0

你确定`$(this).parent()。parent()。find(“.gs-address”)`实际上是在找到你认为它的结果吗? – Pointy 2011-01-12 19:02:11

+0

我确实看到它打开弹出罚款,当我点击结果。但我也看到弹出窗口打开。如果我只是点击地址区域而不是标题,那么它就是你想要的。我错过了什么? – spinon 2011-01-12 19:03:17

+0

我希望能够点击标题,而不是打开链接。然后,弹出地图上的框。换句话说,我想把整个结果看待。 – TIMEX 2011-01-12 19:11:03

回答

0

的HTML代码是:

<div class="gs-title"><a target="_blank" class="gs-title" href="http://www.google.com/maps/place?source=uds&amp;q=pizza&amp;cid=12855512876323852687">California <b>Pizza</b> Kitchen</a></div> 

    <div class="gs-address">... 

所以我认为正确的道路coul'd是:

$("a.gs-title").click(function(){ 

$(this).parent().siblings('.gs-address').click();return false; 
}); 
1

解决。我手动删除了A标签。

// Returns the HTML we display for a result before it has been "saved" 
    LocalResult.prototype.html = function() { 
     var me = this; 
     var container = document.createElement("div"); 
     container.className = "unselected"; 
     container.appendChild(me.result_.html.cloneNode(true)); 
     $(container).find('a').replaceWith(function() { return $(this).contents(); }); 

     return container; 
    }