我正在一个网站上工作并使用 javascript 滚动文本。我正在使用计数器及其工作,但是当它通过条件语句时,它并没有隐藏 div 或保持一致。关于为什么会发生这种情况的任何想法?
谢谢!
html:
<div id="arrow2">
<a id="arrowRight" href="javascript:ltoggle('box');"><img alt="Arrow Right" height="auto" src="images/rightarrow.png"></a>
</div>
<div id="content">
<div class="boxPosition" id="box1">
<p>This is a destination wedding. Come early, and stay late!</p>
</div>
<div class="boxPosition" id="box2">
<p>Festivities will start on Friday, August 16th.</p>
</div>
<div class="boxPosition" id="box3">
<p>The wedding will be on Sunday, August 18th late in the day, so you should plan to take Monday off!</p>
</div>
<div class="boxPosition" id="box4">
<p>a</p>
</div>
<div class="boxPosition" id="box5">
<p>b</p>
</div>
<div class="boxPosition" id="box6">
<p>c</p>
</div>
<div class="boxPosition" id="box7">
<p>d</p>
</div>
<div class="boxPosition" id="box8">
<p>e</p>
</div>
js:
var counter = 1;
var numBoxes = 8;
function toggle(divName){
counter++
var ele = document.getElementById(divName + counter);
console.log(divName + counter);
if(ele.style.display == "block"){
ele.style.display = "none";
}
else{
ele.style.display = "block";
}
if(counter==numBoxes){
counter = 0;
}
}