这是一个用延时循环刷新另一个页面的例子,用以下方法可以实现,
但只能用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)+"%";
alert(WidthP+":"+url); //这里用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>

解决方案 »

  1.   

    lz你的程序运行到 document.write 这段代码后
    打开页面源代码看看就知道是怎么回事了...
      

  2.   

    给个解决方案也好啊,目的是延时循环并同步执行XMLHTTP 返回执行数量并修改某个STYLE的宽度百分比
    document.getElementById("b1").style.width=WidthP;
      

  3.   

    我执行了,看到了源码只有
    document.write 里面的内容,相当于变成新的页面了,不懂,求教
      

  4.   

    document.write 是将内容输入到网页中执行后,页面中当然就没有以前写的程序代码了,自然也就不执行了.
      

  5.   

    document.getElementById("b1").style.width=WidthP;
    谢谢楼上的,那这句是不是也跟document.write一个道理呢
    另外如何改写代码或者用什么方法思路可以实现
    延时循环并同步执行XMLHTTP 返回执行数量并修改某个STYLE的宽度百分比 
    document.getElementById("b1").style.width=WidthP;
      

  6.   

    用$(id).innerHTML = 'xxxx'输出。
      

  7.   

    在页面加载完毕的情况下,使用document.write会清空网页的内容的。
      

  8.   

    document.write以后改变了网页内容,也就没有脚本了,所以脚本内容不能运行了!