这是JSfiddle的链接。
Javascript:
var headerCount;
var timeDelay;
$(document).ready(function () {
headerCount = $('.headerlink').length;
timeDelay = $('.current').attr('ref');
if (undefined != timeDelay) {
timeDelay = "5000"
}
setTimeout("advance()", timeDelay);
});
function advance() {
$('.current').next('.headerlink').addClass('current2');
$('.current').removeClass("current");
$('.current2').addClass('current').removeClass('current2');
if (headerCount == $(".current").index('.headerlink')) {
$('.current').removeClass('current');
$('.headerlink:nth-child(1)').addClass('current');
}
timeDelay = $('.current').attr('ref');
if (undefined != timeDelay) {
timeDelay = "5000"
}
setTimeout("advance()", timeDelay);
}
HTML:
<a ref="5000" class="headerlink current" href="http://www.raceramps.com/12-4thqtr-twenty-five-dollar-rebate.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/4thQTR[25_rebateCheck].jpg" /> </a>
<a class="headerlink" href="http://www.raceramps.com/2012-3rdqtr-25-visa.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/3rdQTR[25VISA_rebate].jpg" /> </a>
<a class="headerlink" href="http://www.raceramps.com/12-4thqtr-twenty-five-dollar-rebate.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/4thQTR[25_rebateCheck].jpg" /> </a>
<a class="headerlink" href="http://www.raceramps.com/12-4thqtr-twenty-five-dollar-rebate.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/4thQTR[25_rebateCheck].jpg" /> </a>
问题:目标是将代码添加.current
到 中next('.headerlink')
,然后.current
从原始中删除。但由于某种原因,它只是删除.current
(它似乎非常快速地添加/删除所有匹配的元素)。
我错过了什么?</p>