我想显示一系列由AJAX生成的表。
以下是我的JS代码。
$(function() {
$(".buttonTEST").on("click",function(e) {
$(".18").toggle( "slow", function showNext() {
$(this).toggle("slow");
$(this).next("table").toggle( "slow", showNext);
});
});
});
18是第一个表的类。
代码工作正常,但显示表并将它们关闭得太快。
我想要的是开盘和下一个开盘之间的暂停。
我试着玩setTimeout
,但最后还是以永无止境的循环和错误结束。
我该怎么做?
答案 0 :(得分:1)
$.fn.slowToggle = function() {
item = $(this);
item.toggle("slow", function() {
setTimeout(function(){
var next = item.next("table");
if(next.length) {
next.slowToggle();
} else {
return null;
}
}, 2000);
});
}
$(".buttonTEST").on("click",function(e) {
$(".18").slowToggle();
});
这是fiddle