日期:2014-05-16  浏览次数:20527 次

怎么才能让一个循环的结果输出到一个文本框内?
我现在非常需要这样一个功能(就象男人需要女人一样,呵呵),希望用javascript里的任意一种循环,在文本框内输出变量每一次循环的值,(说明:不是循环的最终结果),而且还可以控制循环的延迟时间,就是说想让他间隔多长时间循环一次就多长时间循环一次,我是没折了,只看你们这些高手的咯!呵呵,女人是甜的,分也是香的!答上了的同志用分砸!先谢咯!

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<script type= "text/javascript ">
var retime=50; //循环时间 单位毫秒
var res=0;
function re(){
res++;
document.getElementById( "tx ").value=res;
setTimeout( "re() ",retime);
}
window.onload=re;
</script>
</head>

<body>
<input type= "text " id= "tx " />
</body>
</html>
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<script language= "javascript ">
function re(sec){
for (i=1;i <100;i++){
document.getElementById( "tx ").value=i;
var now = new Date();
var exitTime = now.getTime() + sec*1000;
//alert (now.getTime()) ;
while (true) {
now = new Date();
if (now.getTime() > exitTime)
break;
}

}
}

</script>
</head>

<body>
<input type= "text " id= "tx " /> <br>
延迟:秒 <input type= "text " id= "sec " /> <input type= "button " value= "ok " onclick= "re(document.getElementById( 'sec ').value) ">

</body>
</html>

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<script type= "text/javascript ">
var retime=50; //循环时间 单位毫秒
var res=0;
function re(){
res++;
document.getElementById( "tx ").value=res;
setTimeout( "re() ",retime);
}
window.onload=re;
</script>
</head>

<body>
<input type= "text " id= "tx " />
</body>
</html>


------解决方案--------------------
计时器吧?不是叫循环~~~
又或是计时器里执行循环~~
------解决方案--------------------
看看这个吧

http://bbs.51js.com/viewthread.php?tid=66361&highlight=%D4%DD%CD%A3%2B%D4%C2%D3%B0