把setInterval()里的函數(shù)單獨(dú)拉出來(lái)定義,為什么5就不跳表了?是全局變量跟局部變量的問(wèn)題嗎?
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title>?
? <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>??
?</head>
?<body>
? <H4>操作成功</H4>
? <p>
???? <b id="second">5</b>秒后回到主頁(yè) <a href="javascript:goBack();">返回</a>?
? </p>
?
<script type="text/javascript">?
?
?var sec = document.getElementById("second");
?var i = 5;
?function goHome(){
??i--;
??sec.innerHTML = i;
??if(i==1){
???window.location.href =? "http://idcbgp.cn/";
??}
?}
?var timer=setInterval("goHome()"
?,1000);
?
? function goBack(){
?window.history.go(-1);
? }?
? </script>
?</body>
</html>
2017-01-16
可以的啊,我復(fù)制了黏貼你的代碼運(yùn)行后是正常跳表的!
2017-01-14
除了把goHome函數(shù)放在setInterval外,其他的代碼都跟老師的一樣