如何设置每天代码开始的时间以及代码从第二天停止并继续到第二天的时间?
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>
答案 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);