js实现倒计时
2016-07-01 10:34
204 查看
$(function () {
var sec_str = "<%=promotion_second %>";
if (parseInt(sec_str) < 0) {
timer(sec_str.substring(1));
}
else {
timer(sec_str);
}
});
//倒计时
function timer(intDiff) {
$('#hour_show').html("");
$('#minute_show').html("");
$('#second_show').html("");
time_str = window.setInterval(function () {
var day = 0,
hour = 0,
minute = 0,
second = 0;
if (intDiff > 0) {
hour = Math.floor(intDiff / 3600);
minute = Math.floor((intDiff % 3600) / 60);
second = Math.floor(intDiff % 60);
}
if (hour <= 9) hour = '0' + hour;
if (minute <= 9) minute = '0' + minute;
if (second <= 9) second = '0' + second;
$('#hour_show').html(hour);
$('#minute_show').html(minute);
$('#second_show').html(second);
intDiff--;
}, 1000);
}
var sec_str = "<%=promotion_second %>";
if (parseInt(sec_str) < 0) {
timer(sec_str.substring(1));
}
else {
timer(sec_str);
}
});
//倒计时
function timer(intDiff) {
$('#hour_show').html("");
$('#minute_show').html("");
$('#second_show').html("");
time_str = window.setInterval(function () {
var day = 0,
hour = 0,
minute = 0,
second = 0;
if (intDiff > 0) {
hour = Math.floor(intDiff / 3600);
minute = Math.floor((intDiff % 3600) / 60);
second = Math.floor(intDiff % 60);
}
if (hour <= 9) hour = '0' + hour;
if (minute <= 9) minute = '0' + minute;
if (second <= 9) second = '0' + second;
$('#hour_show').html(hour);
$('#minute_show').html(minute);
$('#second_show').html(second);
intDiff--;
}, 1000);
}
相关文章推荐
- uploadify.js
- js控制video的播放和暂停
- Javascript异步编程的4种方法
- js合计
- JavaScript中Number类型,Number,parseInt转换函数特殊情况总结
- js获取日期时间
- JavaScript中的函数
- js中cookie的读取、添加和修改
- json字符串转化为对象
- Jsp,EL表达式的入门
- JSP标签
- 【JavaScript】匿名函数和闭包
- 《JavaScript权威指南》——语法
- js中document.write()使用的两大方面
- JavaScript学习 CodeWars 打怪升级日记 判断输入字符串是否符合IPv4地址标准
- extjs面板布局报错:No center region defined in BorderLayout
- href=”javascript:void(0);的作用, href="#"和 href="###"
- JS交互
- 全面了解JavaScript的数据类型转换
- Intellij IDEA项目中遇到json-default发红的解决办法