一聚教程网:一个值得你收藏的教程网站

热门教程

google 搜索提示

时间:2022-07-02 23:15:58 编辑:袖梨 来源:一聚教程网

 google 搜索提示,google 自动提示   仿google的下拉提示 <%
 Response.ContentType="text/xml"
 search=Trim(request("search"))
 sql="select top 10 [ytitle] from table1 where [ytitle] like '"&search&"%' order by [ytime]"
 rs.open sql,conn,1,1 
 str=""&vbnewline
  str=str&""&vbnewline
 If rs.eof Then 
 Else
  i=1
  Do While Not rs.eof
   str=str&""&vbnewline 
   str=str&"  "&rs("ytitle")&""&vbnewline
   str=str&"
"&vbnewline
  i=i+1
  rs.movenext
  loop
  End If 
  str=str&"
"
  rs.close
  response.write str
%>这种做法是把要搜索的内容以xml 保存然后再用xmldom 读取,缺点是太浪费资源.

xmldom文件代码如下:

var searchReq=createAjaxObj();
function createAjaxObj()
{
 var httprequest=false;
 if(window.XMLHttpRequest)
 {
  httprequest=new XMLHttpRequest();
  if(httprequest.overrideMimeType)
   httprequest.overrideMimeType('text/xml');
 }
 else if (window.ActiveXObject)
 {
  //IE
  try
  {
   httprequest=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
   try
   {
    httprequest=new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch (e)
   {
   }
  }
 }
 return httprequest
}

function searchSuggest()
{
 if (document.getElementById('txtSearch').value.length>0)
 {
  var str=escape(document.getElementById('txtSearch').value);
  url="search.asp?search="+str+ "&t=" +  new Date().getTime();
  searchReq.open("get",url);
  searchReq.onreadystatechange=handleSearchSuggest;
  searchReq.send(null); 
 }
 else
 {
  document.getElementById("search_suggest").innerHTML="";
  document.getElementById("search_suggest").style.display="none";
 }
 
}

function handleSearchSuggest()
{
 if(searchReq.readyState==4)
 {  
   var ss=document.getElementById("search_suggest");  
   ss.innerHTML="";
   s0=searchReq.responseText.length;  
   if (s0>0)
   {
    xmldoc=searchReq.responseXML; 
    var message_nodes=xmldoc.getElementsByTagName("message");
    var n_messages=message_nodes.length;    
    if (n_messages<=0)
    {
     document.getElementById("search_suggest").innerHTML="";
     document.getElementById("search_suggest").style.display="none";
    }
       else
    {
     document.getElementById("search_suggest").style.display="block";
     for (i=0;i      {
      var suggest='

      suggest+='onmouseout="javascript:sugggestOut(this);"';
      suggest+='onclick="javascript:setSearch(this.innerHTML);"';
      suggest +='class="suggest_link">'+message_nodes[i].getElementsByTagName("text")[0].firstChild.data+'
';
      ss.innerHTML +=suggest;
     }    
    }
   }
   else
   {
    document.getElementById("search_suggest").innerHTML="";
    document.getElementById("search_suggest").style.display="none";
   }  
 }
 else
 {
  //alert('网络连接失败');
 }
}

function suggestOver(div_value)
{
 div_value.className='suggest_link_over';
}

function sugggestOut(div_value)
{
  div_value.className='suggest_link';
}

function setSearch(div_value)
{
   document.getElementById("txtSearch").value=div_value;
   document.getElementById("search_suggest").innerHTML="";
   document.getElementById("search_suggest").style.display="none";
}

热门栏目