一、对于跳转页面的操作首先,我们分析需要在页面上输入,可以用div包装这个跳转的指令。在浏览器中输出。
<body>
<div id="demo"></div>
</body>
</html>
二、我们分析,需要确定获取的元素,#demo ,然后确定用定时器设置,setInterval(函数名,时间,我们有时候需要更改数据,更改时间怎么办。我们能不能封装函数呢?所以就用了下面的方法。
var demo = document.getElementById("demo");
var count = 5;
var speed = 1000;
setTimeout(goIndexPage,speed); // 1秒钟之后去执行 goIndexPage这个函数
function goIndexPage() {
//alert(arguments.callee);
count--;
demo.innerHTML = "<a href='http://www.baidu.com'>本页面将在第"+count+"秒钟之后跳转页面</a>";
if(count <= 0)
{
// 如果 count 小于 0 就到了时间了 我们应该跳转页面
window.location.href = "http://www.baidu.com";
}
else
{
setTimeout(arguments.callee,speed); // 递归调用 自己调用自己arguments代表的是实参调用callee.
}
</script>