Javascript/jQuery倒计时计时器未正确初始化

Javascript/jQuery倒计时计时器未正确初始化,javascript,jquery,function,Javascript,Jquery,Function,我有一个倒计时计时器,我已经从原来的修改,但它似乎不工作。我强调的问题是,startCountdown(startDate、deadlineDate、expiredText)没有启动,它返回未定义的。代码中的所有其他内容都按预期启动,并返回正确的结果。有什么想法吗 我已经添加了下面包含控制台日志等的所有信息 jQuery(文档).ready(函数($){ $('.clockdiv')。每个(函数(){ //开始获取所需的值 var startDate=$(this).find(.start”)

我有一个倒计时计时器,我已经从原来的修改,但它似乎不工作。我强调的问题是,
startCountdown(startDate、deadlineDate、expiredText)
没有启动,它返回未定义的。代码中的所有其他内容都按预期启动,并返回正确的结果。有什么想法吗

我已经添加了下面包含控制台日志等的所有信息

jQuery(文档).ready(函数($){
$('.clockdiv')。每个(函数(){
//开始获取所需的值
var startDate=$(this).find(.start”).attr(“rel”);//获取报价的开始日期
var deadlineDate=$(this).find(.end”).attr(“rel”);//获取报价的截止日期
var expiredText=$(this).find(.expired”).attr(“rel”);//获取过期优惠券文本
//结束获取所需的值
函数getTimeRemaining(deadlineDate,startDate){
var pD=Date.parse(deadlineDate);//获取截止日期前的毫秒数
var pS=Date.parse(startDate);//获取自开始日期起的毫秒数
var t=pD-pS;//找出从开始日期到截止日期的毫秒数
var s=Math.floor((t/1000)%60);//计算距离截止日期还有多少秒
var m=Math.floor((t/1000/60)%60);//计算出离截止日期还有多少分钟
var h=数学地板((t/(1000*60*60))%24);//计算截止日期前的小时数
var d=数学地板(t/(1000*60*60*24));//计算截止日期前的天数
return{//返回总剩余时间的值
“total”:t,//返回剩余总时间的值
“days”:d,//返回剩余天数的值
'hours':h,//返回剩余小时数的值
“分钟”:m,//返回剩余分钟数的值
“秒”:s//返回剩余秒数的值
};
}
函数startCountdown(startDate、deadlineDate、expiredText){
var dC=$(this.find('div>.days');//获取时钟的days容器
var hC=$(this.find('div>.hours');//获取时钟的小时容器
var mC=$(this.find('div>.minutes');//获取时钟的分钟容器
var sC=$(this.find('div>.seconds');//获取时钟的秒容器
函数updateLock(startDate、deadlineDate、expiredText){
var t=getTimeRemaining(deadlineDate,startDate);//重新分配t的值作为getTimeRemaining函数的输出
dC.innerHTML=t.days;//设置innerHTML以显示剩余天数
hC.innerHTML=('0'+t.hours).slice(-2);//设置innerHTML以显示剩余的小时数
mC.innerHTML=('0'+t.minutes).slice(-2);//设置innerHTML以显示剩余的分钟数
sC.innerHTML=('0'+t.seconds).slice(-2);//设置innerHTML以显示剩余的秒数
如果(t.总div{
弹性:20%;
填充物:5px;
边界半径:3px;
背景#74b848;
显示:内联块;
}
#clockdiv div>span{
填充:10px;
宽度:100%;
边界半径:3px;
背景:#FFFFFF;
显示:内联块;
}
#clockdiv.smalltext{
垫面:5px;
字体大小:16px;
字体大小:正常;
颜色:#fff;
}



小时

分钟


以下是它的工作版本:

jQuery(文档).ready(函数($){
$('.clockdiv')。每个(函数(){
var self=$(这是);
//开始获取所需的值
var startDate=self.find(“.start”).attr(“rel”);//获取报价的开始日期
var deadlineDate=self.find(“.end”).attr(“rel”);//获取报价的截止日期
var expiredText=self.find(“.expired”).attr(“rel”);//获取过期优惠券文本
//结束获取所需的值
函数getTimeRemaining(deadlineDate,startDate){
var pD=Date.parse(deadlineDate);//获取截止日期前的毫秒数
//var pS=Date.parse(startDate);//获取自开始日期起的毫秒数
var pS=Date.now();
var t=pD-pS;//找出从开始日期到截止日期的毫秒数
var s=Math.floor((t/1000)%60);//计算距离截止日期还有多少秒
var m=Math.floor((t/1000/60)%60);//计算出离截止日期还有多少分钟
var h=数学地板((t/(1000*60*60))%24);//计算截止日期前的小时数
var d=数学地板(t/(1000*60*60*24));//计算截止日期前的天数
return{//返回总剩余时间的值
“total”:t,//返回剩余总时间的值
“days”:d,//返回剩余天数的值
'hours':h,//返回剩余小时数的值
“分钟”:m,//返回剩余分钟数的值
“秒”:s//返回剩余秒数的值
};
}
函数startCountdown(startDate、deadlineDate、expiredText){
var dC=self.find('div>.days');//获取时钟的days容器
var hC=self.find('div>.hours');//获取时钟的小时容器
var mC=self.find('div>.minutes');//获取时钟的分钟容器
var sC=self.find('div>.seconds');//获取时钟的秒容器
函数updatelock(){
var t=getTimeRemaining(deadlineDate,startDate);//重新分配t的值作为getTimeRemaining函数的输出
控制台日志(t);
dC.empty().append($.parseHTML(''+t.days
jQuery(document).ready(function( $ ) {
    $('.clockdiv').each(function() {
        var self = $(this);
        //START Get required values
        var startDate = self.find(".start").attr("rel"); //Gets start date of offer
        var deadlineDate = self.find(".end").attr("rel"); //Gets deadline date of offer
        var expiredText = self.find(".expired").attr("rel"); //Gets expired coupon text
        //END Get required values

        function getTimeRemaining(deadlineDate,startDate) {
            var pD = Date.parse(deadlineDate); //Get the amount of milliseconds until the end date
            //var pS = Date.parse(startDate); //Get the amount of milliseconds since the start date
            var pS = Date.now();
            var t = pD - pS; //Find out how many milliseconds from start date to the deadline date
            var s = Math.floor((t / 1000) % 60); //Works out how many seconds until the deadline
            var m = Math.floor((t / 1000 / 60) % 60); //Works out how many minutes until the deadline
            var h = Math.floor((t / (1000 * 60 * 60)) % 24); //Works out how many hours until the deadline
            var d = Math.floor(t / (1000 * 60 * 60 * 24)); //Works out how many days until the deadline

            return { //Return the value of the total time remaining
                'total': t, //Return the value of the total time remaining
                'days': d, //Return the value of the days remaining
                'hours': h, //Return the value of the hours remaining
                'minutes': m, //Return the value of the minutes remaining
                'seconds': s //Return the value of the seconds remaining
            };
        }

        function startCountdown(startDate,deadlineDate,expiredText) {
            var dC = self.find('div > .days'); //Get the days container of the clock
            var hC = self.find('div > .hours'); //Get the hours container of the clock
            var mC = self.find('div > .minutes'); //Get the minutes container of the clock
            var sC = self.find('div > .seconds'); //Get the seconds container of the clock

            function updateClock() {
                var t = getTimeRemaining(deadlineDate,startDate); //Reassign the value of t to be the output of getTimeRemaining fuction
                console.log(t);

                dC.empty().append($.parseHTML('' + t.days)); //Set the innerHTML to display the days remaining
                hC.empty().append($.parseHTML(('0' + t.hours).slice(-2))); //Set the innerHTML to display the hours remaining
                mC.empty().append($.parseHTML(('0' + t.minutes).slice(-2))); //Set the innerHTML to display the minutes remaining
                sC.empty().append($.parseHTML(('0' + t.seconds).slice(-2))); //Set the innerHTML to display the seconds remaining

                if (t.total <= 0) { //If there is no time remaining then do the following
                    clearInterval(clockLoop); //Stop the 1s looping of the clockLoop
                    self.empty().append($.parseHTML('<p>' + expiredText + '</p>')); //Display the expiredText value inside of the clockdiv
                }

            }
            updateClock(); //Run the updateClock function
            var clockLoop = setInterval(updateClock, 1000); //Define the clockLoop to run the updateClock function every seond
        }

        startCountdown(startDate,deadlineDate,expiredText); //Initiate the startCountdown clock
     });
});