当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - Jquery for click function

问题描述:

I want to be able to click on a thumb and show the larger picture on the gallery. Here is my view.

view

<div class="gallery">

<ul class="slideshow">

<% @images.each do |img|%>

<li>

<%= link_to image_tag(...), :alt => img.name ), img %>

</li>

<% end %>

</ul>

<div class="thumbs">

<% @images.each do |img|%>

<a href="javascript:void(0)" rel="<%= img.images... %>" class="slideshow">

<%= image_tag(...)%>

</a>

<% end %>

</div>

</div>

here is my js code

js

function click() {

$('.thumbs').click(

function() {

var gallery = $(this).attr("rel");

$('ul.slideshow').removeClass('show');

$(this).addClass('show');

$('slideshow').html('<img src="' + gallery + '" />');

return false;

})

}

but it doesn't seem to work. Right now, the larger slideshow also has a setInterval so all the different larger images rotate.

网友答案:

Why r u using this inside the click() function.. You can directly use like this..

$('.thumbs').click(function() {
var gallery = $(this).attr("rel");
$('ul.slideshow').removeClass('show');
$(this).addClass('show');
$('slideshow').html('<img src="' + gallery + '" />');
return false;
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: