简体   繁体   English

重载 javascript 后定时器保持值

[英]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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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