我正在使用此倒计时代码:
var clock = document.getElementById("timeleft"), tdy = new Date(1494979200000);
countdown.setLabels(
'| <span class="time-label">second</span>| <span class="time-label">minute</span> | <span class="time-label">hour<span> | <span class="time-label">day</span> || <span class="time-label">month</span> ||||',
'| <span class="time-label">seconds</span> | <span class="time-label">mins</span> | <span class="time-label">hours</span> | <span class="time-label">days</span> || <span class="time-label">months</span> ||||',
'',
'',
'Out of Time','');
clock.innerHTML = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate(), tdy.getHours(), tdy.getMinutes(), tdy.getSeconds()) ).toString();
setInterval(function(){
clock.innerHTML = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate(), tdy.getHours(), tdy.getMinutes(), tdy.getSeconds()) ).toString();
}, 1000);
如何修改上述代码以在倒计时数字周围添加span标签?提前谢谢。
参考:http://explore.venasolutions.com/Q3-Weekly-Webinar-LP-2.html
答案 0 :(得分:0)
如果您想要准确显示您提供的网址中显示的内容,则必须使用以下代码使用Div标记,
var arr=countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate(), tdy.getHours(), tdy.getMinutes(), tdy.getSeconds()) ).toString();
for(var i=0;i<arr.length;i++){
clock.innerHTML= "<div> "+arr+" </div>";
}
setInterval(function(){
var arr=countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate(), tdy.getHours(), tdy.getMinutes(), tdy.getSeconds()) ).toString();
clock.innerHTML= "<div> "+arr+" </div>";
}, 1000);
如果你想要像你提到的那样在span标签内输入整个文本,你将需要我们以下代码,
var count=countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate(), tdy.getHours(), tdy.getMinutes(), tdy.getSeconds()) ).toString();
var arr=count.split(" ");
clock.innerHTML="";
for(var i=0;i<arr.length;i++){
clock.innerHTML+= "<span> "+arr[i]+" </span>";
}
setInterval(function(){
var count = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate(), tdy.getHours(), tdy.getMinutes(), tdy.getSeconds()) ).toString();
var arr=count.split(" ");
clock.innerHTML="";
for(var i=0;i<arr.length;i++){
clock.innerHTML+= "<span> "+arr[i]+" </span>";
}
}, 1000);