问题
I am using the countdown timer from http://www.jqueryscript.net/time-clock/Extremely-Lightweight-jQuery-Countdown-Timer-Plugin-downCount.html
I would like to add a button that resets the timer. There is no built in functionality, so I wrote my own function to do it. I am very new to javascript and can't get the clock to countdown (works on my site, just not in jsfiddle for some reason) or actually reset. I built a JSFiddle here:
https://jsfiddle.net/9dzu7g6a/
reset function:
function reset(){
var date = new Date();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var dateString = day + '/' + month + '/' + year + ' ' + hour + ':' + minutes + ':' + seconds;
$('.countdown').downCount({
date: dateString,
offset: +.5
});
};
回答1:
You will need to edit the library your using to do this and add the reset function to that as currently it provides no way to stop a timer ones it has started.
This link will help you get started.
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval
来源:https://stackoverflow.com/questions/34707958/countdown-timer-with-reset-function-using-jquery-and-downcount