代码如下,将倒数时间以num传递到倒数函数dCount中,无法实现倒数。
!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<h2>操作成功</h2>
<span id="second"></span>秒后返回主页 <a href="javascript:bcak()">返回</a>
<script type="text/javascript">
dCount(5);
function dCount(num){
var i;
if(num>0){
document.getElementById("second").innerHTML=num;
num--;
i=setTimeout("dCount(num)",1000);
}
else{
clearTimeout(i);
window.open("www.imooc.com","_self");
}
}
function back(){
window.history.back();
}
</script>
</body>
</html>
i=setTimeout("dCount(num)",1000);这一句的递归没有执行,去掉“”应该可以