Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拍卖倒计时jQuery_Javascript_Jquery_Timer_Countdown - Fatal编程技术网

Javascript 拍卖倒计时jQuery

Javascript 拍卖倒计时jQuery,javascript,jquery,timer,countdown,Javascript,Jquery,Timer,Countdown,我正在尝试为我的web应用程序进行拍卖倒计时,但唯一有效的倒计时是最后一个,我如何解决这个问题,我尝试使用浏览器断点,但没有结果 function deployTimersSearch() { var nb = $("div.productFull").find("div.data_exptag").length; var dia = ""; var mes = ""; var ano = "";

我正在尝试为我的web应用程序进行拍卖倒计时,但唯一有效的倒计时是最后一个,我如何解决这个问题,我尝试使用浏览器断点,但没有结果

        function deployTimersSearch() {
        var nb = $("div.productFull").find("div.data_exptag").length;

        var dia = "";
        var mes = "";
        var ano = "";
        var hora = "";
        var minutos = "";
        var segundos = "";

        var arrayContadores = new Array(nb);

        for (var i = 0; i < nb; i++) {
            dia = $("div.productFull").find("div#diatag" + i).text();
            mes = $("div.productFull").find("div#mestag" + i).text();
            ano = $("div.productFull").find("div#anotag" + i).text();
            hora = $("div.productFull").find("div#horatag" + i).text();
            minutos = $("div.productFull").find("div#minutotag" + i).text();
            segundos = "00";

            arrayContadores[i] = $("div#countDowntag" + i).countdown(ano, mes, dia, hora, minutos, segundos);
            arrayContadores[i].start();
        }

    }
函数deployTimersSearch(){
var nb=$(“div.productFull”).find(“div.data_exptag”).length;
var dia=“”;
var mes=“”;
var ano=“”;
var hora=“”;
var minutos=“”;
var segundos=“”;
var arraycontadors=新数组(nb);
对于(变量i=0;i
在这里之前,一切正常

我想问题就在这里:

        <script>
        var before = "";
        var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
        var theyear, themonth, theday, thehour, theminutes, theseconds;

        jQuery.fn.countdown = function (yr, mes, d, h, m, s) {
            $that = $(this);
            var delta = 0;

            var start = function (yr, mes, d, h, m, s) {
                theyear = yr;
                themonth = mes;
                theday = d;
                thehour = h;
                theminutes = m;
                theseconds = s;

                var today = new Date();
                var todayy = today.getYear();
                if (todayy < 1000) todayy += 1900;
                var todaym = today.getMonth();
                var todayd = today.getDate();
                var todayh = today.getHours();
                var todaymin = today.getMinutes();
                var todaysec = today.getSeconds();

                var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;

                var futurestring = montharray[mes - 1] + " " + d + ", " + yr + " " + thehour + ":" + theminutes + ":" + theseconds;

                dd = Date.parse(futurestring) - Date.parse(todaystring) + delta;

                dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
                dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
                dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
                dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);

                if (dday < 0 && dhour < 0 && dmin < 0 && dsec < 1) {
                    alert("ended");
                    return;
                } else $that.html("<span><strong>" + dday + "</strong><span> Days | " + "<span><strong>" + dhour + "</strong></span> Hours | " + "<span><strong>" + dmin + "</strong></span> Minutes");

                setTimeout(function () {
                    start(theyear, themonth, theday, thehour, theminutes, theseconds);
                }, 1000);
            }
            return {
                start: function () {
                    start(yr, mes, d, h, m, s);
                },
                addTime: function (ms) {
                    delta += ms;
                }
            }
        };
        </script>

前var=”;
var montharray=新数组(“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”);
年、月、日、时、分、秒;
jQuery.fn.countdown=函数(yr、mes、d、h、m、s){
$that=$(this);
var-delta=0;
var启动=功能(年、月、日、小时、月、日){
年份=年;
每月=人工编码站;
天=d;
小时=小时;
分钟=m;
秒=秒;
var today=新日期();
var today=today.getYear();
如果(今天<1000)今天+=1900;
var todaym=today.getMonth();
var todayd=today.getDate();
var todayh=today.getHours();
var todaymin=today.getMinutes();
var todaysec=today.getSeconds();
var todaystring=montharray[todaym]+“+todayd+”,“+todaydy+”+“+todaydh+”:“+todaymin+”:“+todaysec;
var futurestring=montharray[mes-1]+“+d+”,“+yr+”+“+thehour+”:“+theminutes+”:“+theseconds;
dd=Date.parse(futurestring)-Date.parse(todaystring)+delta;
dday=数学楼层(dd/(60*60*1000*24)*1);
dhour=数学楼层((dd%(60*60*1000*24))/(60*60*1000)*1);
dmin=数学楼层((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
dsec=数学地板(((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
如果(dday<0&&dhour<0&&dmin<0&&dsec<1){
警报(“结束”);
返回;
}else$that.html(“”+dday+“天“+”“+dhour+”小时“+”“+dmin+”分钟”);
setTimeout(函数(){
开始(年、月、日、小时、分钟、秒);
}, 1000);
}
返回{
开始:函数(){
启动(yr、mes、d、h、m、s);
},
添加时间:函数(毫秒){
δ+=ms;
}
}
};

问题在于,在声明变量时,您正在使用var关键字,因此它们被声明为全局变量,并在计时器之间共享。这应该有效(jsfiddle):

var $that = $(this);
...

var theyear = yr;
var themonth = mes;
var theday = d;
var thehour = h;
var theminutes = m;
var theseconds = s;
...

var dd = Date.parse(futurestring) - Date.parse(todaystring) + delta;

var dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
var dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
var dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
var dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);