简体   繁体   中英

timer keep values after reload of javascript

I have a project on which I am working at the moment, this project is based on the control of the hours of work of an educator. example; the teacher before working, he must start his course while clicking on a button to trigger a miner who will control his number of hours of work. I would like to know how to do if after the teacher to start his course, even if we refresh his page so that the timer continues to count and after his course, he will click on another button for his timer uninitialized. already thank you for your help...

<!DOCTYPE html>
<html>
<head>
<div id="response"></div>
<script>
$(document).ready(function(){

    var x;
    var face;
    $(document).on('click', '.AddCourseProintage', function(){


  var one_second = 1000;
  var one_minute = one_second * 60;
  var one_hour = one_minute * 60;
  var one_day = one_hour * 24;
  var startDate = new Date();
  test = document.getElementById('response');
  x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();
  var now = new Date();
  var elapsed = now - startDate;
  var parts = [];

  parts[0] = '' + Math.floor( elapsed / one_hour );
  parts[1] = '' + Math.floor( (elapsed % one_hour) / one_minute );
  parts[2] = '' + Math.floor( ( (elapsed % one_hour) % one_minute ) / one_second );

  parts[0] = (parts[0].length == 1) ? '0' + parts[0]+'h' : parts[0]+'h';
  parts[1] = (parts[1].length == 1) ? '0' + parts[1]+'mn' : parts[1]+'mn';
  parts[2] = (parts[2].length == 1) ? '0' + parts[2]+'s' : parts[2]+'s';
  test.innerText = parts.join(' : ');

       // If the count down is finished, write some text 


}, 1000);


});
});

</script>
</head>
<body>

</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM