【发布时间】:2022-12-11 15:26:58
【问题描述】:
我从我的函数中使用 javascript 和 php 进行了倒计时,倒计时有效,但现在我想要 3 个选项:
-
如果倒计时超过 24 小时,请显示 te
selector.next(".countdown").html(expiry);date -
如果倒计时为 6 小时或更短时间,请显示计时器
selector.next(".countdown").html(days + "d " + hours + "h " + minutes + "m " + seconds + "s "); -
否则倒计时小于0表示endend
selector.next(".countdown").html(<p>Closed</p>);$(".expiry").each(function() { var expiry = new Date($(this).text()); var selector = $(this) var x = setInterval(function() { var currentDateObj = new Date(); var numberOfMlSeconds = currentDateObj.getTime(); var addMlSeconds = 60 * 60 * 1000; var now = new Date(numberOfMlSeconds - addMlSeconds); var distance = expiry - now; var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); if( distance >= 86400000 && distance < 21600000){ selector.next(".countdown").html(expiry); }else if ( distance <= 21600000 && distance > 0){ selector.next(".countdown").html(days + "d " + hours + "h " + minutes + "m " + seconds + "s "); }else{ selector.next(".countdown").html('<p>error</p>'); } }, 1000); });
【问题讨论】:
-
86400000永远不会小于21600000,条件永远不会通过。也许你在这里需要||而不是&&..? -
它现在总是显示错误 btw
标签: javascript html jquery