【发布时间】:2013-07-26 11:55:29
【问题描述】:
我想使用 JQuery 一个一个地显示/隐藏一个列表,这是我的代码: 名单:
<p>This is the text</p>
<p>This is the text 1</p>
<p>This is the text 2</p>
按钮功能:
$("#hide").on("click", function(event) {
hideList($("p"), 0);
});
下面是隐藏/显示列表的函数:
function hideList(list, index) {
if (index < list.length) {
list.eq(index).toggle(2000, hideList(list, index+1));
} else {
return;
}
}
但是当按钮点击的时候,3个<p>是隐藏在一起的,不是一个一个的。但是这样的代码是有效的,<p>一一显示:
$("#show").on("click", function(event) {
$("p").eq(0).toggle(2000, function() {
$("p").eq(1).toggle(2000, function() {
$("p").eq(2).toggle(2000);
});
});
});
有谁知道是什么导致了这个问题?非常感谢。
【问题讨论】: