关于setTimeout clearTimeout 延时循环中只能用alert显示循环过程,不能用document.write
这是一个用延时循环刷新另一个页面的例子,用以下方法可以实现,
但只能用alert得到循环的过程,用document.write 就不可以,不知道为什么,找了很多资料也没弄明白
希望高人给点指点,迫不得已麻烦各位,谢谢
alert(WidthP+":"+url); //这里用alert就可以正常运行,用document.write或者document.其他方法都不行,请问这是为什么呢
<script language="javascript">var timeUp = 0;var NewsID = "<%=SeleceNewsID%>".split(",");delayRun();//循环执行任务,延时操作function delayRun(code,time){url='http://localhost/keywordsget1.asp?NewsID='+NewsID[timeUp];validateEmail(url);var WidthP = timeUp/NewsID.length;WidthP = Math.round(WidthP * 100)+"%";[color=#FF0000]alert(WidthP+":"+url);[/color] //这里用alert就可以正常运行,用document.write或者document.其他方法都不行,请问这是为什么呢if(timeUp < NewsID.length){timeUp++;var t = setTimeout(function(){delayRun(code,time);},time);}else{ clearTimeout(t);}}//XMLHTTP提交数据并获取网页内容var xmlHttp; function validateEmail(url) { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } xmlHttp.open("GET", url); xmlHttp.onreadystatechange = callback; xmlHttp.send(null); } function callback() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { } } }</script>