以下是指向JSfiddle的鏈接。addClass removeClass滑動條顯示的jQuery問題
的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
(它似乎很快就添加/刪除所有匹配元素)。
我錯過了什麼?
請在您的答案中直接包含相關代碼,理想情況下對所做更改進行一些說明。如果jsfiddle無法訪問,這個答案應該保持相關。 –
當然,我會這樣做 –