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

用innerHTML刷新一个区域的内容时出现闪烁,我写好Demo,高手请进!!!
<table>
<tr>
<td> <div   id= "area "> <select   name=select2   size= "20 "   multiple= "multiple "   style= "width:150px; ">
    <option   value=01> 01 </option> </select> </div> </td> <td> <input   name= "button "   type= "button "   id= "button1 "   onclick= "test(); "   value= "button "> <input   name= "button "   type= "button "   id= "button1 "   onclick= "simulate(); "   value= "simulate   more   click 's "> </td> </tr>
</table>
<script   language= "javascript ">
<!--
var   str1= " <select   name=select1   multiple=\ "multiple\ "   size=20   style=width:150px;> <option   value=11> 11 </option> <option   value=12> 12 </option> </select> ";
var   str2= " <select   name=select2   multiple=\ "multiple\ "   size=20   style=width:150px;> <option   value=21> 21 </option> </select> ";
var   intmark=0;
var   objdivarea=document.all[ "area "];
var   flag=0;  
var   interval=null;  
function   test()
{
if(intmark==0)
{
objdivarea.innerHTML=str1;
intmark=1;
}
else
{
objdivarea.innerHTML=str2;
intmark=0;
}
return   true;
}
function   simulate()
{
    simulate2();      
    interval=window.setInterval( 'simulate2() ',10);  
    //alert(flag);
}
function   simulate2()
{

if(intmark==0)
{
objdivarea.innerHTML=str1;
intmark=1;
}
else
{
objdivarea.innerHTML=str2;
intmark=0;
}
flag++;
if(flag> 98)
{      
  window.clearInterval(interval);
}
}
-->
</script>

------解决方案--------------------
闪是因为把area里的东西重新写了一次又一次,造成视觉上的闪,没法避免的,除非你换种实现方式。