我正在使用这个很棒的插件:http://keith-wood.name/countdown.html
我有3个倒数计时器,上面装有json数组。当我想给它们充电时,它们会堵塞,并出现此错误:
TypeError:inst.options is undefinedjquery.countdown.js:682:1jQuery 4_generateHTML_updateCountdown_updateElemstimerCallBack
这里是我的代码在ajax加载后第一次加载时(处于成功状态)(再生给出x秒::
var timer = [];
$.each(json.element, function (index, value) {
if($.isNumeric(json.regen[i])){
var timer = json.regen[i];
var stat = json.stat[i];
//Creating the countdown for each element
$("#under_"+value).html('+1 in <span id="countdown_'+json.element[i]+'"></span>');
//initialize countdown and loop it at the end.
$('#countdown_'+json.element[i]).countdown({until: timer, compact: true, format: 'MS', onExpiry: function() {
getattribute(stat);
}
});
};
i++;
});
当我单击按钮以刷新那些倒计时时,会出现错误...我该如何解决?
这里是密码笔:https://codepen.io/Logobi/pen/KKdmNby
Thx
似乎还可以,我必须在重新初始化之前检查倒数计时。如果倒计时还没有结束,我会降低它,如果结束了,我会重新加载getattribute。
let oCountdown = $('#countdown_'+[i]+'_'+element[i]);
if(oCountdown.length>0){
oCountdown.countdown('option', "until", timer);
}else{
$("#under_"+elemval).html('+1 in <span id="countdown_'+[i]+'_'+element[i]+'"></span>');
$('#countdown_'+[i]+'_'+element[i]).countdown(
{
until: timer,
format: 'MS',
compact: true,
onExpiry:function() {
getattribute();
}
}
);// format ii:ss
}
这里是codepen中的解决方案:https://codepen.io/Zonecss/pen/jObmdBM