English 中文(简体)
我怎么能够减少每秒使用 j子的超文本元素的价值?
原标题:How can I decrease the value of an HTML element each second using jQuery?

这里我迄今为止所做的事情:

var timer = setInterval(function () {
    $(".auctiondiv .auctiondivleftcontainer .countdown").text(sec--);
}, 1000);

这一工程很重,但之所以出现这一问题,是因为我不得不将<编码>sec<>/code>的开端价值确定下来,而我网页上的每个计票部分的价值相同。 因此,不节省这一价值和减少其价值,可能最好只得到每个尺度的价值,并减少价值,而不节省 Java文任何地方的价值。

我怎么能够将案文放在下调要素(a<p> tag)和从中分出的内容中,将其重新编号为<p> 内容? 我感到困惑的是,我的网页上有许多点击内容,我如何走到一起?

我还必须确保,一旦面值达到零,我就可以做一些事情。 有条件发言。 我想,我可以使用<代码>。

任何指导?

最佳回答

您可使用j Query each方法,在相应的一组内容上加以公布:

var timer = setInterval(function () {
    $(".countdown").each(function() {
        var newValue = parseInt($(this).text(), 10) - 1;
        $(this).text(newValue);
        if(newValue == 0) {
           //Do something
        }
    });
}, 1000);

我先将甄选人改为仅限<代码>。

http://jsfiddle.net/interdream/RhXPC/8/“rel=“nofollow”

问题回答

你们应储存在变数中不止一次使用的内容,以节省资源。

此外,由于各自行为的不同,鼓励使用<代码>>>> 准时。 http://bonsaiden.github.com/Javagust-Garden/#other.timeouts”rel=“nofollow”>here。

// cache elements to save resources
var $countdownElements = $( ".countdown" );

function countDown() {

    $countdownElements.each( function () {
        var $this = $( this ); // again, cache element for later use
        var newValue = parseInt( $this.text(), 10 ) - 1;
        $this.text( newValue );
        if ( newValue == 0 ) {
           //Do something
        }
    });

    // call this function again in 1 second
    setTimeout( countDown, 1000 );
}

countDown();




相关问题
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.

热门标签