js

作者: 趁年轻拼一拼 | 来源:发表于2018-09-02 12:26 被阅读0次

倒计时

var btn = document.getElementById('btn');

var btn1 = document.getElementById('btn1');

btn.onclick = function() {btn1.style.display = 'block';

btn.style.display = 'none';var fun = setInterval(function() {

var date1 = new Date('2018/07/06 18:00:00');

;var date2 = new Date();

var old = date1.getTime();

var now = date2.getTime();

var time = old - now;

var moth = Math.floor(time / (1000 * 60 * 60 * 24));var moth2 = time % (1000 * 60 * 60 * 24);

var hour = Math.floor(moth2 / (1000 * 60 * 60));

var hour2 = time % (1000 * 60 * 60);

var min = Math.floor(hour2 / (1000 * 60));

var min2 = time % (1000 * 60);

var sec = Math.floor(min2 / (1000));

document.getElementById('dome1').innerHTML = '距离暑假还有' + '
';

document.getElementById('dome').innerHTML = +moth + '日' + hour + '时' + min + '分' + sec + '秒';

})

btn1.onclick = function() {btn1.style.display = 'none';btn.style.display = 'block';

clearInterval(fun);

alert('您点击了停止定时,定时定在了' + dome.innerHTML

)}

}

相关文章

网友评论

      本文标题:js

      本文链接:https://www.haomeiwen.com/subject/nmqmwftx.html