[英]Click a rails link_to with jQuery
我试图通过单击谷歌地图标记单击使用jquery的Rails Ajax链接,但不知道如何做到这一点。 这是链接:
sidelistings div
<% @properties.each_with_index do |property,index| %>
<div class="sidelisting" id="<%= index %>">
<div><%= link_to image_tag("http://432.mlsimages.movoto.com/0#{property.mls.last(2)}/tn/#{property.mls}_0.jpg"), {:action => 'show', :id => property.id}, :remote => true %> </div>
我有一张上面有20个标记的google map,它与上述sidelistings
div中的20个属性匹配。 我希望能够单击地图标记,这将单击上面的链接作为其对应的属性。 我已将20个辅助列表的id
匹配到地图标记数组的索引。 这是我在Google Maps代码中的jQuery尝试:
google.maps.event.addListener(markerArray[i], 'click', function(){
var element = this.id;
var sidelisting = document.getElementById(element);
$('sidelisting:a').click();
});
上面的代码在控制台中没有引发任何错误,但是单击地图标记没有任何作用,我在做什么错?
弄清楚了,我错了很多,这是工作代码:
google.maps.event.addListener(markerArray[i], 'click', function(){
var index = markerArray.indexOf(this);
$('#' + index + ' a').click();
});
我不知道我是否必须在$()
内以加号和还需要a标记的空格来构造选择器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.