下面是我的代码,数据少时速度还可以,现在有3000多条的数据,显示太慢了,请高手帮忙解决一下,拜托了。
<html>
<head>
<LINK href="../../common/style_desk.css" rel=stylesheet>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>船舶报告信息</title>
</head>
<body> 中文船名:<input name="ZWCM" type="text" class="inputbg" id="ZWCM" value="" size="12">
</body>
</html>
<script>
 //http://192.168.0.2/vhf/cbnm.html 
 var rmopo = window.createPopup();  function rm(i,oct,h)
 {   
  var i2=eval(i);
  var oct=eval(oct);
  var w=eval(i).offsetWidth;
  var h=eval(h);
  var lefter = i2.offsetLeft-1; var topper = i2.offsetHeight;
  rmopo.document.body.innerHTML = oct.innerHTML;
  rmopo.document.body.style.border="1px solid #3162A6";
  rmopo.document.body.style.background="#F6F6F6";
  rmopo.show(0, topper, w, h, i2);
  }  loadcombobox(document.all.ZWCM);  function loadcombobox(obj)
 {
  var obj = eval(obj)
  //theListArrayV = al_v;
  //theListArrayT = al_t;

  var tempStr='<DIV id="'+obj.id+'showcombox" style="position:absolute;visibility:hidden">'
+'<DIV class="ac_menu" id="'+obj.id+'ListDiv" style="FONT-SIZE: 12px; Z-INDEX: 10; POSITION: absolute;OVERFLOW-Y:auto; WIDTH:expression('+obj.offsetWidth+'-1);">'
     tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('昇航')+'" textvalue="'+htmlEncode('昇航')+'">'+htmlEncode('昇航')+'</DIV>';   tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('昇航027')+'" textvalue="'+htmlEncode('昇航027')+'">'+htmlEncode('昇航027')+'</DIV>';   tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('昇航397')+'" textvalue="'+htmlEncode('昇航397')+'">'+htmlEncode('昇航397')+'</DIV>';   tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('昇航398')+'" textvalue="'+htmlEncode('昇航398')+'">'+htmlEncode('昇航398')+'</DIV>';   tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('昇航666')+'" textvalue="'+htmlEncode('昇航666')+'">'+htmlEncode('昇航666')+'</DIV>';   tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('安吉168')+'" textvalue="'+htmlEncode('安吉168')+'">'+htmlEncode('安吉168')+'</DIV>';   tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('安吉218')+'" textvalue="'+htmlEncode('安吉218')+'">'+htmlEncode('安吉218')+'</DIV>';   tempStr+='<DIV class="ac_menuitem" onmouseover="this.style.backgroundColor=\'#D6DEEC\';" onmouseout="this.style.backgroundColor=\'\';" onclick="this.selectedflag=1;parent.document.all.'+obj.id+'.value=this.value;parent.document.all.'+obj.id+'.blur();" style="cursor:default;" value="'+htmlEncode('安吉289')+'" textvalue="'+htmlEncode('安吉289')+'">'+htmlEncode('安吉289')+'</DIV>';
  
  tempStr+='</DIV></DIV>';
  
  obj.insertAdjacentHTML("afterEnd",tempStr);
  obj.onfocus=AC_OnFocus;
  obj.onclick=AC_OnFocus;
  obj.onblur =AC_OnBlur;
  obj.onkeydown=AC_OnKeyDown;
  obj.autoComplete="off";
  obj.onpropertychange=AC_OnPropertyChange;
 }  function AC_OnFocus(obj)
 {
if(obj==null) obj=event.srcElement;
popmenu=eval(obj.id+"showcombox");
rm(obj,popmenu,130);
AC_OnPropertyChange(obj);
 }  function AC_OnBlur(obj)
 {
  rmopo.hide();
 }  function AC_OnPropertyChange(obj)
 {
  if(obj==null) obj=event.srcElement;

  var dv = eval("rmopo.document.all['"+obj.id+"ListDiv']");
  theListDiv = dv
  if(theListDiv==null) return;
  var theListDivChildren=theListDiv.children;

  theListDiv.selectedIndex=-1;
  var theFirstVisibleIndex=-1;

  var objValue=obj.value;
  //alert(objValue);

  for(var i=0;i<theListDivChildren.length;i++)
  {
   //alert(theListDiv.children[i].textvalue.search(objValue));
   //if(theListDiv.children[i].textvalue.indexOf(objValue)==0)
   if(theListDiv.children[i].textvalue.search(objValue)!=-1)
   {
  if(theFirstVisibleIndex==-1) theFirstVisibleIndex=i;
  theListDivChildren[i].style.backgroundColor="#F6F6F6";
  theListDivChildren[i].style.display="";
   }
   else
   theListDivChildren[i].style.display="none";
   if(theListDiv.selectedIndex==-1 && theListDiv.children[i].textvalue==objValue)
   {
 theListDiv.selectedIndex=i;
   }
  }
  
  if(theListDiv.selectedIndex==-1 && theFirstVisibleIndex!=-1) 
  {
  theListDiv.selectedIndex=theFirstVisibleIndex;
  }
  
  if(theListDiv.selectedIndex!=-1)
  {
  theListDiv.children[theListDiv.selectedIndex].style.backgroundColor="#D6DEEC";
  }
  
  adjustListDivScroll(obj);
 }  function AC_OnKeyDown(obj)
 {
  if(obj==null) obj=event.srcElement;

  var AC_TAB = 9;
  var AC_ENTER = 13;
  var AC_UP_ARROW = 38;
  var AC_DOWN_ARROW = 40;

  var dv = eval("rmopo.document.all['"+obj.id+"ListDiv']");
  theListDiv = dv
  if(theListDiv==null) return ;

  var keyCode=event.keyCode;
  if(keyCode==AC_ENTER) keyCode=event.keyCode=AC_TAB;

  if(keyCode==AC_TAB && theListDiv.selectedIndex!=-1) 
  {
   obj.value=theListDiv.children[theListDiv.selectedIndex].value;
   //document.all.TT.value = 'OK';
   rmopo.hide() ;
  }
  
  if(keyCode==AC_UP_ARROW && theListDiv.selectedIndex!=-1)
  {
   for(var i=theListDiv.selectedIndex-1;i>-1;i--)
   {
if(theListDiv.children[i].style.display!="none")
{
 theListDiv.children[theListDiv.selectedIndex].style.backgroundColor="#F6F6F6";
 theListDiv.selectedIndex=i;
 theListDiv.children[theListDiv.selectedIndex].style.backgroundColor="#D6DEEC";
 adjustListDivScroll(obj);
 break;
}
   }
  }
 
  if(keyCode==AC_DOWN_ARROW && theListDiv.selectedIndex!=-1)
  {
   for(var i=theListDiv.selectedIndex*1+1;i<theListDiv.children.length;i++)
   {
if(theListDiv.children[i].style.display!="none")
{
 theListDiv.children[theListDiv.selectedIndex].style.backgroundColor="#F6F6F6";
 theListDiv.selectedIndex=i;
 theListDiv.children[theListDiv.selectedIndex].style.backgroundColor="#D6DEEC";
 adjustListDivScroll(obj);
 break;
}
   }
   return;
  }
 
 }  function adjustListDivScroll(obj)
 {
  if(obj==null) obj=event.srcElement;

  var dv = eval("rmopo.document.all['"+obj.id+"ListDiv']");
  theListDiv = dv

  if ( theListDiv==null || theListDiv.selectedIndex==-1 ) return ;
  var i=theListDiv.selectedIndex;
  if((theListDiv.children[i].offsetTop<theListDiv.scrollTop)||(theListDiv.children[i].offsetTop>theListDiv.scrollTop+120))
   theListDiv.scrollTop=theListDiv.children[i].offsetTop-85;
 }  function htmlEncode(str)
 {
  if(str==null) return "";
  str=str.replace(/</ig,"&lt;")
  str=str.replace(/>/ig,"&gt;");
  str=str.replace(/"/ig,"&quot;");
  return str;
 }</script>

解决方案 »

  1.   

    你要在一个suggestion里显示几千条数据?
      

  2.   

    没有任何办法~虽然可能会调优一点,但是显示几千条数据在浏览器上本身就是灾难。
    建议你显示前10条。你看看google或者baidu一下子显示几千条提示吗
      

  3.   

    AJAX就是为了实现这种效果出现的。
    当数据量很大的时候,象你这样把数据全放到HTML里以备智能提示,速度上受不了。所以,利用AJAX,可以每次只按照用户输入而返回少量符合的数据。如果要求在用户没输入的情况下,点击文本框输出下拉菜单中含有一定的数据,可以在返回这个页面的时候,象目前一样,只设置开头的若干条数据即可。然后根据用户的输入,再用AJAX去取相符的数据。关于AJAX智能补全实例,可以看看下面的资源
    http://download.csdn.net/down/2114854/HanYingLong_2009http://home.searchfull.net:8080/2406717-ajax+jquery+%E8%87%AA%E5%8A%A8+.html