- 积分
- 61483
注册时间2013-9-9
最后登录1970-1-1
在线时间 小时
|
发表于 2014-3-13 13:04:22
|
显示全部楼层
- </script>
- <div id="mhkjslTimeNum"></div>
- <script type="text/javascript">
- /**
- * @author jianminlu
- * @update 2014-03-10 10:14
- * @name {Function} countDown
- * @param {Object}
- * @domId {String} domID
- * @startTime {String} 2015/1/30 年/月/日 时:分:秒
- * @endTime {String 2014/1/30 年/月/日 时:分:秒
- * @flag {Boolean} true / false
- */
- (function(W, D){
- var countDown = W['countDown'] = function(o){
- return new _countDown(o);
- },
- _countDown = function(o){
- this.endTime = o.endTime;
- this.startTime = o.startTime;;
- this.dom = D.getElementById(o.domId);
- this.i = 0;
- this.flag = o.flag;
- this.init();
- };
- _countDown.prototype = {
- auto: function(){
- var _this = this;
- setTimeout(function(){
- _this.init(_this.endTime, _this.domId);
- }, 1000);
- },
- ten: function(t){
- if(t < 10){
- t = "0" + t;
- }
- return t;
- },
- init: function(){
- var _this = this,
- time = 0;
- _this.i ++;
-
- if(_this.flag){
- time = (new Date(_this.endTime).getTime() - new Date(_this.startTime).getTime() + 1000 * _this.i) / 1000
- }else{
- time = (new Date(_this.endTime).getTime() - new Date(_this.startTime).getTime() - 1000 * _this.i) / 1000
- }
- var day = _this.ten(Math.floor(time / (60 * 60 * 24))),
- hour = _this.ten(Math.floor(time /(60 * 60)) - day * 24),
- minute = _this.ten(Math.floor(time /60) - (day * 24 * 60) - (hour * 60)),
- second = _this.ten(Math.floor(time) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60));
-
- _this.dom.innerHTML = "<b class='day'>" + day + "</b><b class='xi'>" + hour + "</b><b class='min'>" + minute + "</b><b class='sou'>" + second + "</b>";
- _this.auto();
- }
- }
- })(window, document);
- // SSI时间格式
-
- countDown({
- domId: "mhkjslTimeNum", // 绑定dom
- startTime: '2014/3/8 1:20:00', // 结束时间 年/月/日 时:分:秒
- endTime: '2014/03/13 19:57:31', // 结束时间 年/月/日 时:分:秒
- flag: true // 是否为正计时 true 正计时 false 倒计时
- });
- </script>
复制代码 |
|