我有一个全局变量“isOnSecond”,它最初被设置为falseJavaScript逻辑问题
这是连接到检测布尔值if语句,如果这是真的有些动作被执行,然后布尔是设置回false。因此我希望这项行动能够在一半时间内完成。
我的问题是这样的,我知道我在这个函数中有逻辑问题,但是在这一点上我似乎无法想出一个解决方案。
我应该如何重新使用我想要的逻辑工作这个功能?
function transComplete()
{
slideTransStep = 0;
crtSlideIndex = nextSlideIndex;
alert(isOnSecond);
// for IE filters, removing filters re-enables cleartype
if (nextSlide.style.removeAttribute)
nextSlide.style.removeAttribute("filter");
// show next slide
showSlide((crtSlideIndex >= totalSlides) ? 1 : crtSlideIndex + 1);
if (isOnSecond == true){
//unhighlight all controls
for (var i=0; i < slidesControllersCollection.length; i++){
if (slidesControllersCollection[i].className === slideHighlightClass)
slidesControllersCollection[i].className = ""; }
// highlight the control for the next slide
if (slidesControllersCollection[i].className === slideHighlightClass)
document.getElementById("slide-control-" + crtSlideIndex+1).className = slideHighlightClass;
isOnSecond = false;
}
isOnSecond = true;
}
首先,我会建议将所有if语句包装在'{}'中。但你总是在最后设置'isOnSecond'为'true',所以这可能是问题 –
谢谢你们,得到它的工作,学校的男孩错误:) – user2696787
你需要_deperly_ indent你的代码。问题应该是显而易见的。 – SLaks