开发者

Cycling through a collection of records with jQuery?

I have an array of Questions, stored in @questions. I want the user to be able to have next and back buttons to cycle through the questions, using jQuery to change the question div's contents.开发者_C百科

So, for example, here's the jQuery code [.js.erb] that I would use for the question partial:

$(document).ready(function(){
  $("#question").html("<strong><%= @question.name %></strong><% insert_more_code_here %>");
});

How would I design the page where I want the users to be able to cycle through the questions? I know I would probably be using something in a each block but I do not want to show all the questions at the same time. Thanks!


Output all of the questions in your HTML and use CSS to hide the ones you don't want to show right away. Then use jQuery to change their visibility either using jQuery.hide() and .show() or by toggling a CSS class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜