javascript刷新页面后继续运行,不从头执行
我现在一刷新页面就继续显示第一张图表了,并不切换图表。
希望大家可以给我具体的代码,谢谢。
var g1 = document.getElementById('g1');
var g2 = document.getElementById('g2');
var timer = null;
var a = true;
function change(){
if (a) {
g1.style.display = 'block';
g2.style.display = 'none';
a = false;
}else{
g1.style.display = 'none';
g2.style.display = 'block';
a = true;
}
}
timer = setInterval(change,5000);
忘了一点代码,,在if和else的最后还有一句 window.location.reload(); 展开
<div id = "g1"><img src="https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/pic/w%3D230/sign=91b5680396dda144da096bb182b7d009/95eef01f3a292df57d9c6005bd315c6034a87347.jpg"/></div>
<div id = "g2" style="display:none"><img src="https://gss0.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/pic/w%3D230/sign=74d1f5d430adcbef013479059cae2e0e/5d6034a85edf8db16f60b0740823dd54564e7450.jpg"/></div>
<script>
function turnpic(){
var g1 = document.getElementById('g1');
var g2 = document.getElementById('g2');
var timer = null;
var a = true;
function change(){
if (a) {
g1.style.display = 'block';
g2.style.display = 'none';
a = false;
}else{
g1.style.display = 'none';
g2.style.display = 'block';
a = true;
}
}
timer = setInterval(change,500);
}
turnpic();
</script>
帮你完善了,你可以看一下附件
谢谢,不过还是没解决问题……