设置每天代码开始的时间以及代码停止并在第二天从该点继续的时间

时间:2018-06-21 17:14:12

标签: javascript html

如何设置每天代码开始的时间以及代码从第二天停止并继续到第二天的时间?

var timeInterval = 1000; //value in ms you want the code to run

setInterval(function(){
  var frame = document.getElementById('frame');
  var prev = frame.src.match(/.*?=(\d*)/)[1];
  var next = (+prev) + 1;
  frame.src = frame.src.replace(/id=(\d*)/, "id="+next);
  console.log(frame.src);
}, timeInterval);
<iframe id='frame' src="https://www.example.com/id=108559" frameBorder="0" scrolling="no">
</iframe>

1 个答案:

答案 0 :(得分:0)

使用本地存储。尝试以下操作:

if (!localStorage.getItem("count")) {
  var count = 0;
  localStorage.setItem("count", count);
} else {
  var count = localStorage.getItem("count");
}

var timeInterval = 1000; //value in ms you want the code to run

setInterval(function() {
  console.log(count++);
}, timeInterval);