<script type="text/javascript">
function getDown(){
var gundong = document.getElementsByClassName("gundong");
var L = gundong.length;
var show = 1;
for(var i=0;i<L;i++){
if(gundong[i].style.display=='block'){
show=i;
break;
}
}
if(show+4<L){
gundong[show].style.display='none';
gundong[show+4].style.display='block';
}
}
function getUp(){
var gundong = document.getElementsByClassName("gundong");
var L = gundong.length;
var show = 1;
for(var i=0;i<L;i++){
if(gundong[i].style.display=='block'){
show=i;
break;
}
}
if(show-1>=0&&show+4<=L){
gundong[show-1].style.display='block';
gundong[show+3].style.display='none';
}
}
</script>
以下为html代码:
<div id="main">
<div class="gundong" id="liudong" style="display:block">1</div>
<div class="gundong" id="liudong" style="display:block">2</div>
<div class="gundong" id="liudong" style="display:block">3</div>
<div class="gundong" id="liudong" style="display:block">4</div>
<div class="gundong" id="liudong" style="display:none">5</div>
<div class="gundong" id="liudong" style="display:none">6</div>
<div class="gundong" id="liudong" style="display:none">7</div>
</div>
<input type='button' οnclick="getUp()" value="上一个"> <input type='button' οnclick="getDown()" value="下一个">以下效果图: