页面多倒计时显示最新修改

2016-07-07 15:01 来源:www.chinab4c.com 作者:ecshop专家

因为一个项目的需要对官方的lefttime.js进行了修改实现一个页面支持多个倒计时。
.dwt内容
通过循环显示拍卖
//定义要显示时间的层


//把数据库的时间隐藏在input内
//<input type='hidden' name="auction_time" id='hid_{$auction.act_id}' value='{$auction.auc_due_time}_{$auction.act_id}'>

lefttime.js

/* $Id : lefttime.js 4865 2007-01-31 14:04:10Z paulgao $ */
/* *
* 给定一个剩余时间(s)动态显示一个剩余时间.
* 当大于一天时。只显示还剩几天。小于一天时显示剩余多少小时,多少分钟,多少秒。秒数每秒减1 *
*/
// 初始化变量
var auctionDate = 0;
var _GMTEndTime = 0;
var showTime = "leftTime";
var _day = '天';
var _hour = ':';
var _minute = ':';
var _second = '';
var _end = 'end';
var cur_date = new Date();
var startTime = cur_date.getTime();
var Temp;
var temp_id;
var timerID = null;
var timerRunning = false;
function showtime()
{
now = new Date();
var ts = parseInt((startTime - now.getTime()) / 1000) + auctionDate;
var dateLeft = 0;
var hourLeft = 0;
var minuteLeft = 0;
var secondLeft = 0;
var hourZero = '';
var minuteZero = '';
var secondZero = '';

if (ts < 0)
{
ts = 0;
CurHour = 0;
CurMinute = 0;
CurSecond = 0;
}
else
{
dateLeft = parseInt(ts / 86400);
ts = ts - dateLeft * 86400;
hourLeft = parseInt(ts / 3600);
ts = ts - hourLeft * 3600;
minuteLeft = parseInt(ts / 60);
secondLeft = ts - minuteLeft * 60;
}
if (hourLeft < 10)
{
hourZero = '0';
}
if (minuteLeft < 10)
{
minuteZero = '0';
}
if (secondLeft < 10)
{
secondZero = '0';
}
if (dateLeft > 0)
{
Temp = dateLeft + _day + hourZero + hourLeft + _hour + minuteZero + minuteLeft + _minute + secondZero + secondLeft + _second;
}
else
{
if (hourLeft > 0)
{
Temp = hourLeft + _hour + minuteZero + minuteLeft + _minute + secondZero + secondLeft + _second;
}
else
{
if (minuteLeft > 0)
{
Temp = minuteLeft + _minute + secondZero + secondLeft + _second;
}
else
{
if (secondLeft > 0)
{
Temp = secondLeft + _second;
}
else
{
Temp = '';
}
}
}
}
if (auctionDate <= 0 || Temp == '')
{
Temp = "" + _end + "";
stopclock();
}
//document.getElementById("hid_auction_"+auction_id).innerHTML = Temp;
if (document.getElementById("hid_auction_"+auction_id))
{
document.getElementById("hid_auction_"+auction_id).innerHTML = Temp;
}
}
var timerID = null;
var timerRunning = false;
function stopclock()
{
if (timerRunning)
{
clearTimeout(timerID);
}
timerRunning = false;
}
function macauclock()
{
stopclock();
showtime();
}

function onload_leftTime()
{
// alert(end_time);
/* 第一次运行时初始化语言项目 */
try
{
_GMTEndTime = end_time;
// 剩余时间
_day = day;
_hour = hour;
_minute = minute;
_second = second;
_end = end;
}
catch (e)
{
}
var objArray = document.getElementsByName('auction_time');
for(i=0;i<(objArray.length);i++)
{
if (objArray[i].id.indexOf("hid_")>-1)
{
objHid = document.getElementById("hid_" + objArray[i].id.substring(objArray[i].id.indexOf("_")+1));
ids=objHid.value.split("_");
var tmp_val = parseInt(ids[0]) - parseInt(cur_date.getTime() / 1000 + cur_date.getTimezoneOffset() * 60);
auction_id =ids[1];
auctionDate = tmp_val;

macauclock(temp_id);
//
try
{
initprovcity();
}
catch (e)
{
}
}
}
//if (_GMTEndTime > 0)
//{
// if (now_time == undefined)
// {
// }
// else
// {
//var tmp_val = parseInt(_GMTEndTime) - now_time;
// }
// if (tmp_val > 0)
// {
//auctionDate = tmp_val;
// }
//}
timerID = setTimeout("onload_leftTime()", 1000);
timerRunning = true;
}

回答:
好帖子,顶一个。

多谢楼主分享啊

说的不是很明白,看不懂

好像挺复杂的!不懂的话,看看这篇文章对倒计时的改法:http://www.whoii.com/blog/?p=50

多谢分享有演示吗

不会用~~~

多谢分享。。。。

楼主能说一下怎么调用吗》?

auc_due_time这是从何而来?任意编造的吗?

该怎么调用?

楼主能不能再热心一点点呢???先谢了!!!




你关注一下 我会在下周内 录制这个多倒计时的视频

太好了!谢谢!密切关注中!