0
A
回答
0
<span class="countdown" rel="30">0:30</span><br/>
<span class="countdown" rel="60">1:00</span><br/>
<span class="countdown" rel="1800">30:00</span><br/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
// Initialization
$(document).ready(function(){
// Replace <span class="countdown"> rel content with the expiry epoch time
var date = new Date(); // This gives you an epoch date in milliseconds
$('span.countdown').each(function(){
// We do rel*1000 to convert to milliseconds, cause rel is in seconds
$(this).attr('rel', date.getTime()+parseInt($(this).attr('rel'))*1000);
});
// Set an interval so updateCountdown() is called every second
setInterval('updateCountdown()', 1000);
});
// Update, called every second
function updateCountdown() {
var date = new Date(); // This gives you an epoch date in milliseconds
// For each <span class="countdown">
$('span.countdown').each(function(){
// Get time left in milliseconds
var timeLeft = parseInt($(this).attr('rel')) - date.getTime();
// Convert from milliseconds to seconds
timeLeft = Math.round(timeLeft/1000);
// Set to 0 if negative
if (timeLeft < 0) timeLeft = 0;
// Extract minutes and seconds for display
var secs = timeLeft % 60;
var mins = (timeLeft-secs)/60;
// Change <span> content
$(this).text(mins+':'+(secs<10?'0':'')+secs);
});
}
</script>
1
您可以使用JavaScript来实现,从上述ANS影响
标记
<body>
<div id="countdown"></div>
</body>
的Javascript
function countdown(remain) {
var countdown = document.getElementById("countdown"),
timer = setInterval(function() {
countdown.innerHTML = (remain%60 < 10 ? "0": "") + remain %60;
if (--remain < 0) { clearInterval(timer); }
},1000);
}
countdown(20);
相关问题
- 1. 时间跨度倒计时
- 2. 倒计时时间的Android
- 3. 变迁倒计时时间
- 4. 倒计时Unix时间
- 5. 建设时间倒计时
- 6. 设置时间倒计时
- 7. 安卓倒计时计时器时间
- 8. 定时器,倒计时,时间
- 9. 定时器倒计时时间格式
- 10. 倒计时使用图像
- 11. jQuery倒计时 - 每日倒计时,还有次要倒计时?
- 12. 倒计时不像预期的那样倒计时
- 13. Android如何使倒计时像倒计时钟?
- 14. Vue2:瞬间JS倒计时
- 15. JQuery倒计时器不倒计时
- 16. Js倒计时只倒计时一次
- 17. C#timer_Tick()倒计时2步倒计时
- 18. jQuery倒计时不正确倒计时
- 19. 倒计时 - iPhone倒数计时器
- 20. 修复倒计时倒数计时器
- 21. JS倒计时不倒计时
- 22. 倒计时图像时负载视图
- 23. 的JavaScript/jQuery的时间倒计时
- 24. 日期时间倒计时,截止
- 25. 每日倒计时到特定时间
- 26. 倒计时基于出货时间
- 27. db中多行的倒计时时间
- 28. 时间戳倒计时进入负面
- 29. 时间跨度减秒表倒计时
- 30. Javascript开放时间倒计时
。如何在每小时之前添加日期计数? – 2010-11-20 17:25:34
替换“var secs = timeLeft%60; var mins =(timeLeft-secs)/ 60;”部分是由提取小时和天的东西组成。 – 2010-11-24 15:57:52