我的页面上有以下div
:
<div id="page1">
Some content
</div>
<div id="page2">
More content
</div>
<div id="page3">
Even more content
</div>
在页面底部,我有两个按钮Continue
和Back
-我需要做的是根据用户输入显示和隐藏div。
默认情况下,当用户单击page1
page2 Continue'
第1页和第3页is shown and
Back are hidden - if the user clicks the
page1`时,应显示button then
并隐藏其他内容,依此类推。
我对如何在jQuery中实现此功能有完整的想法-欢迎任何帮助。
php大神给出的解决方案
您需要将这些元素放在容器中,然后使用prev
和next
遍历它们。像这样:
$('.next').click(function() {
$('.sequence-container div').hide();
var $next = $('.sequence-container div:visible').next();
$next.length ? $next.show() : $('.sequence-container div:first').show();
});
$('.prev').click(function() {
$('.sequence-container div').hide();
var $prev = $('.sequence-container div:visible').prev();
$prev.length ? $prev.show() : $('.sequence-container div:last').show();
});
Example fiddle
更新
为了防止循环开始/结束,请使用以下命令:
$('.next').click(function() {
var $next = $('.sequence-container div:visible').next();
if ($next.length) {
$('.sequence-container div').hide();
$next.show();
}
});
$('.prev').click(function() {
var $prev = $('.sequence-container div:visible').prev();
if ($prev.length) {
$('.sequence-container div').hide();
$prev.show();
}
});
Updated fiddle
Python:同时在for循环中添加到列表列表 - python我想用for循环外的0索引值创建一个新列表,然后使用for循环添加到相同的列表。我的玩具示例是:import random data = ['t1', 't2', 't3'] masterlist = [['col1', 'animal1', 'an…
如何根据子列表的长度对列表列表进行排序[重复] - pythonThis question already has answers here: Sorting Python list based on the length of the string (7个答案) 5年前关闭。 我有以下清单a = [['a', 'b', 'c'], ['d'…
从CSV文件创建字典 - python我正在尝试编写一个Python脚本,该脚本将从CSV文件中获取输入,然后将其推入字典格式(我使用的是Python 3.x)。我使用下面的代码读取CSV文件,并且可以正常工作:import csv reader = csv.reader(open('C:\\Users\\Chris\\Desktop\\test.csv'), delimit…
如何获取Python中所有内置函数的列表 - python当我们从中获取关键字列表时,如何从Python提示符中获取Python中所有内置函数的列表? python大神给出的解决方案 更新:关于__builtins__或__builtin__可能会有一些混淆。What’s New In Python 3.0建议使用builtins 将模块__builtin__重命名为builtins(删除下划线, 添加一个“ s”…
如何在列表的字典中取消列表的列表? - python我有一个这样的清单:list = [{'item1': value1, 'item2': [{'tinyitem21': tinyvalue21, 'tinyitem22': tinyvalue22}]}, {'item3': [{'tinyitem…