為什么將倒數代碼函數設置傳遞參數就不能倒數了呢
代碼如下,將倒數時間以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.xianlaiwan.cn","_self");
? ? ?}
}
function back(){
? ? window.history.back();
}
? ?
?</script>?
</body>
</html>
2016-03-20
i=setTimeout("dCount(num)",1000);這一句的遞歸沒有執行,去掉“”應該可以