请问实用setTimeout方法为什么不能实现倒计时?
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<span id="txt">5</span>
<span>秒倒计时</span>
<script type="text/javascript">
var i = 5;
var tim = function() {
i--;
document.getElementById("txt").innerHTML = i;
setTimeout("tim()", 1000);
};
</script>
</body>
</html>
我实用setInterval成功实现了倒计时,但是为什么用setTimeout不行?我哪里写错了么?