我的一个 Rails View 中有一个 div,我想让它完全可点击:
<% @objects.each do |f| %>
<div class="overlay" >
<%= link_to image_tag("play.png"), f %>
</div>
我如何使 div 类覆盖跟随 link_to |f| jQuery 中的对象?我在另一个 StackOverflow 问题中发现了这一点,我想针对上述情况对其进行自定义:
$('.overlay').click( function(event) {
var clicked_div = $(this);
# do stuff with the event object and 'this' which
# represent the element you just clicked on
});
谢谢!
最佳答案
你试过给 a
标签一个类吗?
<% @objects.each do |f| %>
<%= link_to image_tag("play.png"), f, class: 'overlay' %>
...
<% end %>
这最终会创建类似的东西
<a href='/some_address' class='overlay'><img src="play.png" alt="something" /></a>
关于javascript - 使用 jQuery 在 Rails 中可点击 Div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23231075/