`
hrsvici412
  • 浏览: 72538 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

JavaScript实践——提交后3秒返回当前页

阅读更多

用到window对象的setTimeout() 方法和setInterval() 方法。

 

setTimeout()方法设置暂停,改方法有两个参数,执行的指定代码和暂停的毫秒数;要取消未执行的暂停,调用clearTimeout()方法。

setInterval()方法用于每隔指定的时间间隔,重复执行指定的代码;参数同上,取消调用clearInterval()方法。

 

  <body onload="setTimeout('window.history.back()', 5000)">
  	<input type="hidden" value="3" id="hid">
 	<span id="num">3</span> 秒自动返回刚才页面!
  </body>

 

 

<script type="text/javascript">
	function back(){
		var num = document.getElementById("hid").value;
		document.getElementById("hid").value = --num;
		var value = document.getElementById("hid").value;
		document.getElementById("num").innerHTML ="<font color='red'>"+value+"</font>";
	}
	window.setInterval('back()',1000)
</script>
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics