-1

我想从我的倒计时中删除分钟和秒,然后添加月份.. 这怎么做???

http://techcongress.net/demo/

CSS: http ://techcongress.net/demo/modules/mod_sp_countdown/assets/css/sp_countdown.css

4

1 回答 1

0

这就是 javascript 做你的倒计时:

    <script type="text/javascript">
//<![CDATA[
window.addEvent('domready', function() {
function calcage(secs, num1, num2, starthtml, endhtml, singular, plural) {
s = ((Math.floor(secs/num1))%num2).toString();
z = ((Math.floor(secs/num1))%num2);
if (LeadingZero && s.length < 2)
{
s = "0" + s;
}
return starthtml
+ '<div class="sp_countdown_int"> '
+ s + '</div>'
+ '<div class="sp_countdown_string"> '
+ ((z<=1)?singular:plural)
+ '</div>'
+ endhtml;
}
function CountBack(secs) {
if (secs < 0) {
document.getElementById("sp_countdown_cntdwn144").innerHTML = '<div class="sp_countdown_finishtext">'+FinishMessage+'</div>';
return;
}
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000,
'<div class="sp_countdown_days">','</div>',' Day', ' Days'));
DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24,
'<div class="sp_countdown_hours">','</div>',' Hr', ' Hrs'));
DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60,
'<div class="sp_countdown_mins">','</div>', ' Min', ' Mins'));
DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60,
'<div class="sp_countdown_secs">','</div>', ' Sec', " Secs"));
document.getElementById("sp_countdown_cntdwn144").innerHTML = DisplayStr;
if (CountActive)
setTimeout(function(){
CountBack((secs+CountStepper))
}, SetTimeOutPeriod);
}
function putspan(backcolor, forecolor) {
}
if (typeof(BackColor)=="undefined")
BackColor = "";
if (typeof(ForeColor)=="undefined")
ForeColor= "";
if (typeof(TargetDate)=="undefined")
TargetDate = "07/24/2013 12:00 AM";
if (typeof(DisplayFormat)=="undefined")
DisplayFormat = "%%D%% %%H%% %%M%% %%S%% ";
if (typeof(CountActive)=="undefined")
CountActive = true;
if (typeof(FinishMessage)=="undefined")
FinishMessage = "Finally we are here";
if (typeof(CountStepper)!="number")
CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
LeadingZero = true;
CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
putspan(BackColor, ForeColor);
var dthen = new Date(TargetDate);
var dnow = new Date();
if(CountStepper>0)
ddiff = new Date(dnow-dthen);
else
ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);
});
//]]>
</script> 

编辑它以满足您的需要,这将包括计算一个月的秒数

DisplayStr = DisplayFormat.replace(/%%MN%%/g, calcage(secs,2592000,12,
'<div class="sp_countdown_months">','</div>',' Month', ' Months'));
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,30,
'<div class="sp_countdown_days">','</div>',' Day', ' Days'));

添加月份并删除分钟和秒

 DisplayFormat = "%%MN%% %%D%% %%H%%";

您会看到遇到的问题是一个月(不含 2 月)在 30 天和 31 天之间切换,因此脚本需要更好的计算,才能正确计算月份...

希望这会有所帮助,如果不是,我们都需要更多地了解 javaScript ;)

于 2013-05-08T15:58:54.280 回答