所以我有一个倒计时手表,从你设置的日期和时间开始下降。小时到0。例如,我设置了1天,每当有一天到期时,仍然存在与样式的div,我怎样才能在当天到期时只剩下几小时来删除该div?手表看起来像 https://i.gyazo.com/83866f9d620d6c87e39ce43b64c92956.png 代码是
var countdown_text = '<span class="theme-watch days">' + days +
'<spam style="font-size:17.5px">' + day_string + '</span>' +
'</span>' +
'<span class="theme-watch hours">' + dig(hours, 2) + '</span>' +
'<span class="theme-watch minutes">' + dig(minutes, 2) + '</span>' +
'<span class="theme-watch seconds">' + dig(seconds, 2) + '</span>' +
"<span id='countdown_miliseconds' class='theme-watch'>" + dig(miliseconds, 3) + "</span>";
答案 0 :(得分:0)
您可以使用if
子句或三元运算符:
var countdown_text = (days > 0) ? '<span class="theme-watch days">'+days+' <span style="font-size:17.5px">'+day_string+'</span></span>' : '';
countdown_text += '<span class="theme-watch hours">'+dig(hours,2)+'</span>'+'<span class="theme-watch minutes">'+dig(minutes,2)+'</span><span class="theme-watch seconds">' + dig(seconds,2)+'</span>'+"<span id='countdown_miliseconds' class='theme-watch'>"+dig(miliseconds,3)+"</span>"; }
ternary operator是写“if
condition
的简写,然后值是x else
它是
相当于
if(days > 0){
var countdown_text = '<span class="theme-watch days">'+days+' <span style="font-size:17.5px">'+day_string+'</span></span>';
}else{
var countdown_text = '';
}