$(document).ready(function()
{
$("#next").click(function()
{
if ($(".divs div:visible").next().length != 0)
{
$(".divs div:visible").next().show().prev().hide();
if($('.divs').find('div').last())
{
$("#next").hide();
}
}
return false;
});
}
html:
<div class="divs">
<div class="cls1">1</div>
<div class="cls2">2</div>
<div class="cls3">3</div>
<div class="cls4">4</div>
<div class="cls5">5</div>
<div class="cls6">6</div>
<div class="cls7">7</div>
</div>
<a id="next">next</a>
答案 0 :(得分:1)
问题在于您的代码:
if($('.divs').find('div').last())
{
$("#next").hide();
}
首次点击时会返回true
,导致第一次点击按钮时隐藏按钮。你需要做的是检查可见div之后是否没有元素,当你隐藏它时。这应该可以解决问题:
$("#next").click(function()
{
if ($(".divs div:visible").next().length != 0)
{
$(".divs div:visible").next().show().prev().hide();
if ($(".divs div:visible").next().length == 0)
{
$("#next").hide();
}
}
return false;
});
答案 1 :(得分:0)
$("#next").click(function()
{
if ($(".divs div:visible").next().length != 0)
{
$(".divs div:visible").next().show().prev().hide();
}
else {
$('#next').hide();
return false;
}
});
}