当我点击上一个和下一个符号时,只有1.jpg和2.jpg img有效,3.jpg从不出现(我只能在1.jpg和2.jpg之间导航)。控制台显示没有错误。我已经看了几个小时了,我真的不认为我的代码有什么不对 CSS:
String sql = String.format("SELECT * FROM %s WHERE name = ?", table);
HTML:
img {width: 100%;}
#slideshow {position: relative;}
.prev, .next {cursor: pointer;position:absolute; top: 50%;}
.next {left: 99%;}
JavaScript的:
<div id="slideshow">
<a class="prev" onclick="slideshow(-1)">❮</a>
<a class="next" onclick="slideshow(1)">❯</a>
<img src="1.jpg">
<img src="2.jpg">
<img src="3.jpg">
</div>
答案 0 :(得分:0)
i是一个始终初始化为0和0的局部变量,它永远不会变为2.需要使用全局变量来保留当前活动图像索引的副本。
var activeImgIndex = 0;
function slideshow(n) {
var imgEs = document.getElementById('slideshow').getElementsByTagName('img');
var l = imgEs.length;
activeImgIndex += n;
if(activeImgIndex >= l || activeImgIndex < 0) {activeImgIndex = 0;}
switch(activeImgIndex) {
case 0:
imgEs[0].style.display = 'block';
imgEs[1].style.display = 'none';
imgEs[2].style.display = 'none';
break
case 1:
imgEs[0].style.display = 'none';
imgEs[1].style.display = 'block';
imgEs[2].style.display = 'none';
break
case 2:
imgEs[0].style.display = 'none';
imgEs[1].style.display = 'none';
imgEs[2].style.display = 'block';
break
default:
imgEs[0].style.display = 'block';
imgEs[1].style.display = 'none';
imgEs[2].style.display = 'none';
}
}
slideshow(0);
&#13;