settimeout 回调函数

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>

<script type="text/javascript">
window.onload=function(){
var btn=document.getElementById("btn");
var num=document.getElementById("num");
var a=0;
btn.onclick=function(){

function addNumber(){
num.value=a;
a++;
setTimeout(addNumber,1000);
}
addNumber();
}

}
</script>

</head>

<body>

 


<input type="button" id="btn" value="点击增加">
<input type="text" id="num">

</body>
</html>

posted @ 2017-08-24 18:10  gxw123  阅读(1564)  评论(0)    收藏  举报