wordpress不用插件实现倒计时的功能
Posted hwa3020
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wordpress不用插件实现倒计时的功能相关的知识,希望对你有一定的参考价值。
前面介绍了wordpress自定义样式倒计时插件jcountdown ,插件的话不受主题更换的影响,如何需要用代码实现的话,下面给大家分享不用插件如何实现倒计时功能。
第一步新增一个js文件 countdown.js,代码如下:
function ShowCountDown(prefix,year,month,day,hourd,minuted,seconded){
var now = new Date();
if( typeof(hourd) == "undefined" ) hourd=23;
if( typeof(minuted) == "undefined" ) minuted=59;
if( typeof(seconded) == "undefined" ) seconded=59;
var endDate = new Date(year, month-1, day, hourd, minuted,seconded);
var leftTime=endDate.getTime()-now.getTime();
var leftsecond = parseInt(leftTime/1000);
var day=Math.floor(leftsecond/(60*60*24));
day = day < 0 ? 0 : day;
var hour=Math.floor((leftsecond-day*24*60*60)/3600);
hour = hour < 0 ? 0 : hour;
var minute=Math.floor((leftsecond-day*24*60*60-hour*3600)/60);
minute = minute < 0 ? 0 : minute;
var second=Math.floor(leftsecond-day*24*60*60-hour*3600-minute*60);
second = second < 0 ? 0 : second;
//var day2 = (day<10?"0"+day:day);
var hour2 = (hour<10?"0"+hour:hour);
var minute2 = (minute<10?"0"+minute:minute);
var second2 =