我正在尝试创建一个简单的倒数计时器,该计时器在完成或达到0时发出蜂鸣声。
<script>
var countDownDate = new Date("Aug 31, 2018 00:00:00").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - 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);
document.getElementById("demo").innerHTML = hours + " h"
+ minutes + " m " + seconds + " sec";
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "Text";
}
}, 1000);
</script>