English 中文(简体)
在四舍五入的四舍五入位数中,每四舍五入到哪一类员额的最佳方式是什么?
原标题:what s the best way to add a class to the div with a class of post every 4 seconds using jquery?

在四舍五入的四舍五入位数中,每四舍五入到哪一类员额的最佳方式是什么?

<div class="34 post">
<img width="311" height="417" src="#" class="#" alt="newspapers" />
<h2><a href="#">Headline News Part 2</a></h2>
<p>testing new content</p>
</div>

<div class="9 post">
<img width="311" height="417" src="#" class="#" alt="newspapers" />
<h2><a href="#">Headline News Part 2</a></h2>
<p>testing new content</p>
</div>

<div class="6 post">
<img width="311" height="417" src="#" class="#" alt="newspapers" />
<h2><a href="#">Headline News Part 2</a></h2>
<p>testing new content</p>
</div>

so i want the first to have a class of "display" then after 4 seconds, i want to remove the class on that one and add it to the second one. and then after 4 more seconds, remove it from the second and add it to the third. when it gets to the end it loops back around.

问题回答
var $postDivs = $( div.post ), // assuming these won t change
    i = -1,
    CLASS_NAME =  foo ;

setInterval(function () {
    $postDivs.eq(i).removeClass(CLASS_NAME);
    i = (i+1) % $postDivs.length;
    $postDivs.eq(i).addClass(CLASS_NAME);
}, 4000);

http://jsfiddle.net/mattball/k2sJy/

如果你想对新闻物品进行简单而明确的轮换,你可尝试。 页: 1 彩虹/a”





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签