如何让程序按照文本框中的秒数进行倒计时?
这是我的代码,直接运行,num是空,总是要程序运行一次,num才变化
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<!--先编写好网页布局-->
<h2>操作成功</h2>
<p><span id="countnum">10</span>秒后回到首页 <a href="javascript:window.history.forward()">返回</a></p>
<form action="" name="form1">
<input type="button" name="" value="开始"onclick="count()" id="button1">
<input type="button" name="" value="停止" id="button2" onclick="stop()">
<input type="text" name="" value="" placeholder="" id="second">
<script type="text/javascript">
var num = parseInt(document.getElementById("second").value)
var i
function count(){
if (num>0) {
window.document.getElementById("countnum").innerHTML = num
document.getElementById("button1").disabled = true
} else{
document.getElementById("button1").disabled = false
window.location.href = "http:www.baidu.com"
};
num--
i = setTimeout("count()", 1000)
}
function stop () {
clearTimeout(i)
document.getElementById("button1").disabled = false
// body...
}
//获取显示秒数的元素,通过定时器来更改秒数。
//通过window的location和history对象来控制网页的跳转。
</script>
</form>
</body>
</html>