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

最后40分请教:如何刷新页面?谢谢大家,什么我的不能
<script>
function   a(){
strUserlist= "1-小李-25-27-f1.gif-0|2-小三-12-12-f2.gif-1 ";
var   userArr=strUserlist.split( "| ");
var   len=userArr.length;
removeAllTR();
for(var   i=0;i <len;i++){
var   newArr=userArr[i].split( "- ");
var   ilen=newArr.length;
var   trObj=document.createElement( "tr ");
trObj.onclick=user(newArr[0]);
var   tdObj1=document.createElement( "td ");
tdObj1.innerText=newArr[4];
trObj.appendChild(tdObj1);
var   tdObj2=document.createElement( "td ");
tdObj2.innerText=newArr[1];
trObj.appendChild(tdObj2);
var   table=document.getElementById( "t1 ");
table.firstChild.appendChild(trObj);
}
}
function   removeAllTR(){
var   table=document.getElementById( "t1 ");
var   len=table.rows.length;
for(var   i=1;i <len;i++){
table.deleteRow(i);
}
}
function   user(id){
return   function(){
window.open( "chating.aspx?id= "+id);
}
}
//每隔1秒更新
window.setTimeout(a,   1000);       //为什么不起作用.
</script>
</head>
<body   onload=a()>
<table   id=t1   border=1>
<TR> <TD> 头像 </TD> <TD> name </TD> </TR>
</table>


------解决方案--------------------
刷新页面?

location.reload() 不行吗?
------解决方案--------------------
<script>
function a(){
strUserlist= "1-小李-25-27-f1.gif-0|2-小三-12-12-f2.gif-1 ";
var userArr=strUserlist.split( "| ");
var len=userArr.length;
removeAllTR();
for(var i=0;i <len;i++){
var newArr=userArr[i].split( "- ");
var ilen=newArr.length;
var trObj=document.createElement( "tr ");
trObj.onclick=user(newArr[0]);
var tdObj1=document.createElement( "td ");
tdObj1.innerText=newArr[4];
trObj.appendChild(tdObj1);
var tdObj2=document.createElement( "td ");
tdObj2.innerText=newArr[1];
trObj.appendChild(tdObj2);
var table=document.getElementById( "t1 ");
table.firstChild.appendChild(trObj);
}
}
function removeAllTR(){
var table=document.getElementById( "t1 ");
var len=table.rows.length;
for(var i=1;i <len;i++){
table.deleteRow(1);
}
}
function user(id){
return function(){
window.open( "chating.aspx?id= "+id);
}
}
//每隔1秒更新
window.setInterval(a, 1000); //为什么不起作用.
</script>
</head>
<body onload=a()>
<table id=t1 border=1>
<TR> <TD> 头像 </TD> <TD> name </TD> </TR>
</table>

==============
改了两个地方:
1.table.deleteRow(i);改成:table.deleteRow(1);
2.setTimeout 改成:setInterval