返回列表 回复 发帖

[原创] ajax之搜索提示

[原创] ajax之搜索提示

大家都使用过google或者xunlei的搜索,输入关键字后可以出现相关提示,是个不错的功能,今天就在这里给大家把我的拙作给大家分享

博客现在由于空间问题暂时关闭,所以实例效果现在已经无法看到,如果你有问题可以qq我:174171262
截图:


代码下载:
本帖隐藏的内容需要回复才可以浏览


数据库表:

  1. CREATE TABLE `xqbar`.`suggest` (
  2. `id` INT NOT NULL AUTO_INCREMENT ,
  3. `title` VARCHAR( 100 ) NOT NULL ,
  4. `hits` INT NOT NULL DEFAULT '0',
  5. PRIMARY KEY ( `id` )
  6. ) ENGINE = InnoDB

  7. insert into suggest(title,hits)values('xqbar.com',100);
  8. insert into suggest(title,hits)values('www.xqbar.com',410);
  9. insert into suggest(title,hits)values('http://xqbar.com',700);
  10. insert into suggest(title,hits)values('mail:xqbar.com',200);
  11. insert into suggest(title,hits)values('ftp:xqbar.com',100);
  12. insert into suggest(title,hits)values('http://www.xqbar.com',70)
复制代码
search.php
(关于php我也是接触不久,下面的php如果罗嗦还望高手指点)
返回的信息字符串要为 xxx1|xxx2$200|100 前后对应

  1. <?php
  2. if($_GET["action"]!=''){
  3.    #获取用户输入的关键字
  4.    $keyword=$_GET["keyword"];
  5.    #过滤关键字
  6.    $keyword=str_replace("[","[[]",$keyword);
  7.    $keyword=str_replace("&","[&]",$keyword);
  8.    $keyword=str_replace("%","[%]",$keyword);
  9.    $keyword=str_replace("^","[^]",$keyword);
  10.    #链接数据库
  11.    $conn=mysql_connect("localhost","xqbar","xqbaradmin");
  12.    #选择数据库
  13.    @mysql_select_db("xqbar") or die('sorry');
  14.    mysql_query('set names utf-8');
  15.    #查询语句
  16.    $sql="select title,hits from suggest where title like '%".$keyword."%' order by hits desc limit 10";
  17.    $result=mysql_query($sql);
  18.    #循环得到查询结果,返回字符串
  19.    #格式为 结果1|结果2$结果1点击次数|结果2点击次数
  20.    if($result){
  21.    $i=1;$title='';$hits='';
  22.    while($row=mysql_fetch_array($result,MYSQL_BOTH))
  23.    {
  24.      $title=$title.$row['title'];
  25.    $hits=$hits.$row['hits'];
  26.    if($i<mysql_num_rows($result))
  27.   {
  28.    $title=$title."|";
  29.    $hits=$hits."|";
  30.   }
  31.   $i++;
  32.     }
  33.    }
  34.    mysql_close();
  35. }
  36. ?>
  37. <?php echo $title.'js代码[code]

  38. 引入prototye.js有朋友说这个库太大,或者把,不习惯的朋友可以使用jquery.js框架或者直接创建ajax对象,这个我就不想说了,这里直接引用prototye.js框架
  39. <script type="text/javascript" src="prototype.js"></script>
  40. 创建层和显示查询结果的js代码
  41. <script type="text/javascript">
  42. //定义变量lastindex 表示为鼠标在查询结果上滑动所在位置,初始为-1
  43. var lastindex=-1;
  44. //定义变量flag 表示是否根据用户输入的关键字进行ajax查询,flase为允许查询 true为禁止查询
  45. var flag=false;
  46. //返回的查询结果生成的数组长度
  47. var listlength=0;
  48. //创建自定字符串,优化效率
  49. function StringBuffer(){this.data=[];}
  50. //赋值
  51. StringBuffer.prototype.append=function(){this.data.push(arguments[0]);return this;}
  52. //输出
  53. StringBuffer.prototype.tostring=function(){return this.data.join("");}
  54. //去掉字符串两边空格
  55. String.prototype.Trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
  56. //隐藏函数 主要是隐藏显示的提示下拉层和iframe,关于iframe下面在说其作用
  57. function hiddensearch()
  58. {
  59. $('rlist').style.display="none";
  60. $('rFrame').style.display="none";
  61. }
  62. //显示函数 主要是显示的提示下拉层和iframe 参数num,根据该参数控制要显示提示层和iframe的高度
  63. function showsearch(num)
  64. {
  65.   $('rlist').style.display='';
  66.   $('rFrame').style.display='';
  67.   //这里我定义每个返回查询结果的提示高度为20px,其中提示层总高度又加了num,是因为我在定义样式时使用了padding一个像素
  68.   $('rlist').style.height=num*20+num+'px';
  69.   //同样定位iframe的高度
  70.   $('rFrame').style.height=num*20+num+'px';
  71. }
  72. //返回文本输入框的坐标函数,参数element为要返回的对象,参数offset可选为offsetLeft|offsetTop 分别表示为该对象距离左窗口上角的绝对位置
  73. //利用这个函数可以定位我们要显示的提示层位置,使提示层正确的显示在文本输入框下面
  74. function getposition(element,offset)
  75. {
  76.     var c=0;
  77.     while(element)
  78.     {
  79.         c+=element[offset];
  80.         element=element.offsetParent
  81.     }
  82.     return c;
  83. }
  84. //创建提示层函数 包括提示层和为了避免在文本输入框下面出现select下拉选框时我们的提示层不能再select之上的iframe
  85. //可以理解为当文本输入框下有select下拉选框时从底向上依次为 select下拉选框-iframe-提示层
  86. function createlist()
  87. {
  88. //创建提示层
  89. var listDiv=document.createElement("div");
  90. //提示层id
  91. listDiv.id="rlist";        
  92. listDiv.style.zIndex="2";
  93. listDiv.style.position="absolute";
  94. listDiv.style.border="solid 1px #000000";
  95. listDiv.style.backgroundColor="#FFFFFF";
  96. listDiv.style.display="none";
  97. listDiv.style.width=$('keyword').clientWidth+"px";
  98. listDiv.style.left=getposition($('keyword'),'offsetLeft')+1.5+"px";
  99. listDiv.style.top =(getposition($('keyword'),'offsetTop')+$('keyword').clientHeight +3)+"px";

  100. var listFrame=document.createElement("iframe");
  101. listFrame.id="rFrame";
  102. listFrame.style.zIndex="1";
  103. listFrame.style.position="absolute";
  104. listFrame.style.border="0";
  105. listFrame.style.display="none";
  106. listFrame.style.width=$('keyword').clientWidth+"px";
  107. listFrame.style.left=getposition($('keyword'),'offsetLeft')+1+"px";
  108. listFrame.style.top =(getposition($('keyword'),'offsetTop')+$('keyword').clientHeight +3)+"px";
  109. document.body.appendChild(listDiv);      
  110. document.body.appendChild(listFrame);
  111. }
  112. function setstyle(element,classname)
  113. {
  114. switch (classname)
  115.     {
  116.      case 'm':
  117.        element.style.fontSize="12px";
  118.     element.style.fontFamily="arial,sans-serif";
  119.     element.style.backgroundColor="#3366cc";
  120.     element.style.color="black";
  121.     element.style.width=$('keyword').clientWidth-2+"px";
  122.     element.style.height="20px";
  123.           element.style.padding="1px 0px 0px 2px";
  124.           if(element.displaySpan)element.displaySpan.style.color="white"
  125.     break;
  126.      case 'd':
  127.        element.style.fontSize="12px";
  128.     element.style.fontFamily="arial,sans-serif";
  129.     element.style.backgroundColor="white";
  130.     element.style.color="black";
  131.     element.style.width=$('keyword').clientWidth-2+"px";
  132.     element.style.height="20px";
  133.           element.style.padding="1px 0px 0px 2px";
  134.           if(element.displaySpan)element.displaySpan.style.color="green"
  135.     break;
  136.   case 't':
  137.        element.style.width="80%";
  138.     if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="left";
  139.     else element.style.styleFloat="left";
  140.     element.style.whiteSpace="nowrap";
  141.     element.style.overflow="hidden";
  142.     element.style.textOverflow="ellipsis";
  143.     element.style.fontSize="12px";
  144.     element.style.textAlign="left";
  145.     break;
  146.   case 'h':
  147.        element.style.width="20%";
  148.     if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="right";
  149.     else element.style.styleFloat="right";
  150.     element.style.textAlign="right";
  151.     element.style.color="green";
  152.     break;
  153.     }
  154. }
  155. function focusitem(index)
  156. {
  157.   if($('item'+lastindex)!=null)setstyle($('item'+lastindex),'d');
  158.   if($('item'+index)!=null)
  159.   {
  160.    setstyle($('item'+index), 'm');
  161.    lastindex=index;
  162.   }
  163.   else $("keyword").focus();
  164. }
  165. function searchclick(index)
  166. {
  167.   $("keyword").value=$('title'+index).innerHTML;
  168.   flag=true;
  169. }
  170. function searchkeydown(e)
  171. {
  172. if($('rlist').innerHTML=='')return;
  173.   var keycode=(window.navigator.appName=="Microsoft Internet Explorer")?event.keyCode:e.which;
  174.   //down
  175.   if(keycode==40)
  176.   {
  177. if(lastindex==-1||lastindex==listlength-1)
  178. {
  179.   focusitem(0);
  180.   searchclick(0);
  181. }
  182. else{
  183.   focusitem(lastindex+1);
  184.   searchclick(lastindex+1);
  185. }
  186.   }
  187. if(keycode==38)
  188. {
  189. if(lastindex==-1)
  190. {
  191.   focusitem(0);
  192.   searchclick(0);
  193. }
  194. else{
  195.   focusitem(lastindex-1);
  196.   searchclick(lastindex-1);
  197. }
  198. }
  199. if(keycode==13)
  200. {
  201.   focusitem(lastindex);
  202.   $("keyword").value=$('title'+lastindex).innerText;
  203. }   
  204. if(keycode==46||keycode==8){flag=false;ajaxsearch($F('keyword').substring(0,$F('keyword').length-1).Trim());}
  205. }
  206. function showresult(xmlhttp)
  207. {
  208. var result=unescape(xmlhttp.responseText);
  209. if(result!=''){
  210.     var resultstring=new StringBuffer();
  211.        var title=result.split('搜索框[code]
  212. <form id="form1" name="form1" method="post" action="">
  213.       <b>输入搜索关键字</b>
  214.     <input name="keyword" type="text" class="inputblue" id="keyword" maxlength="20" style="width:300px;" />
  215. </form>
复制代码
就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6.$hits;?>[/code]js代码


  1. 引入prototye.js有朋友说这个库太大,或者把,不习惯的朋友可以使用jquery.js框架或者直接创建ajax对象,这个我就不想说了,这里直接引用prototye.js框架
  2. <script type="text/javascript" src="prototype.js"></script>
  3. 创建层和显示查询结果的js代码
  4. <script type="text/javascript">
  5. //定义变量lastindex 表示为鼠标在查询结果上滑动所在位置,初始为-1
  6. var lastindex=-1;
  7. //定义变量flag 表示是否根据用户输入的关键字进行ajax查询,flase为允许查询 true为禁止查询
  8. var flag=false;
  9. //返回的查询结果生成的数组长度
  10. var listlength=0;
  11. //创建自定字符串,优化效率
  12. function StringBuffer(){this.data=[];}
  13. //赋值
  14. StringBuffer.prototype.append=function(){this.data.push(arguments[0]);return this;}
  15. //输出
  16. StringBuffer.prototype.tostring=function(){return this.data.join("");}
  17. //去掉字符串两边空格
  18. String.prototype.Trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
  19. //隐藏函数 主要是隐藏显示的提示下拉层和iframe,关于iframe下面在说其作用
  20. function hiddensearch()
  21. {
  22. $('rlist').style.display="none";
  23. $('rFrame').style.display="none";
  24. }
  25. //显示函数 主要是显示的提示下拉层和iframe 参数num,根据该参数控制要显示提示层和iframe的高度
  26. function showsearch(num)
  27. {
  28.   $('rlist').style.display='';
  29.   $('rFrame').style.display='';
  30.   //这里我定义每个返回查询结果的提示高度为20px,其中提示层总高度又加了num,是因为我在定义样式时使用了padding一个像素
  31.   $('rlist').style.height=num*20+num+'px';
  32.   //同样定位iframe的高度
  33.   $('rFrame').style.height=num*20+num+'px';
  34. }
  35. //返回文本输入框的坐标函数,参数element为要返回的对象,参数offset可选为offsetLeft|offsetTop 分别表示为该对象距离左窗口上角的绝对位置
  36. //利用这个函数可以定位我们要显示的提示层位置,使提示层正确的显示在文本输入框下面
  37. function getposition(element,offset)
  38. {
  39.     var c=0;
  40.     while(element)
  41.     {
  42.         c+=element[offset];
  43.         element=element.offsetParent
  44.     }
  45.     return c;
  46. }
  47. //创建提示层函数 包括提示层和为了避免在文本输入框下面出现select下拉选框时我们的提示层不能再select之上的iframe
  48. //可以理解为当文本输入框下有select下拉选框时从底向上依次为 select下拉选框-iframe-提示层
  49. function createlist()
  50. {
  51. //创建提示层
  52. var listDiv=document.createElement("div");
  53. //提示层id
  54. listDiv.id="rlist";        
  55. listDiv.style.zIndex="2";
  56. listDiv.style.position="absolute";
  57. listDiv.style.border="solid 1px #000000";
  58. listDiv.style.backgroundColor="#FFFFFF";
  59. listDiv.style.display="none";
  60. listDiv.style.width=$('keyword').clientWidth+"px";
  61. listDiv.style.left=getposition($('keyword'),'offsetLeft')+1.5+"px";
  62. listDiv.style.top =(getposition($('keyword'),'offsetTop')+$('keyword').clientHeight +3)+"px";

  63. var listFrame=document.createElement("iframe");
  64. listFrame.id="rFrame";
  65. listFrame.style.zIndex="1";
  66. listFrame.style.position="absolute";
  67. listFrame.style.border="0";
  68. listFrame.style.display="none";
  69. listFrame.style.width=$('keyword').clientWidth+"px";
  70. listFrame.style.left=getposition($('keyword'),'offsetLeft')+1+"px";
  71. listFrame.style.top =(getposition($('keyword'),'offsetTop')+$('keyword').clientHeight +3)+"px";
  72. document.body.appendChild(listDiv);      
  73. document.body.appendChild(listFrame);
  74. }
  75. function setstyle(element,classname)
  76. {
  77. switch (classname)
  78.     {
  79.      case 'm':
  80.        element.style.fontSize="12px";
  81.     element.style.fontFamily="arial,sans-serif";
  82.     element.style.backgroundColor="#3366cc";
  83.     element.style.color="black";
  84.     element.style.width=$('keyword').clientWidth-2+"px";
  85.     element.style.height="20px";
  86.           element.style.padding="1px 0px 0px 2px";
  87.           if(element.displaySpan)element.displaySpan.style.color="white"
  88.     break;
  89.      case 'd':
  90.        element.style.fontSize="12px";
  91.     element.style.fontFamily="arial,sans-serif";
  92.     element.style.backgroundColor="white";
  93.     element.style.color="black";
  94.     element.style.width=$('keyword').clientWidth-2+"px";
  95.     element.style.height="20px";
  96.           element.style.padding="1px 0px 0px 2px";
  97.           if(element.displaySpan)element.displaySpan.style.color="green"
  98.     break;
  99.   case 't':
  100.        element.style.width="80%";
  101.     if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="left";
  102.     else element.style.styleFloat="left";
  103.     element.style.whiteSpace="nowrap";
  104.     element.style.overflow="hidden";
  105.     element.style.textOverflow="ellipsis";
  106.     element.style.fontSize="12px";
  107.     element.style.textAlign="left";
  108.     break;
  109.   case 'h':
  110.        element.style.width="20%";
  111.     if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="right";
  112.     else element.style.styleFloat="right";
  113.     element.style.textAlign="right";
  114.     element.style.color="green";
  115.     break;
  116.     }
  117. }
  118. function focusitem(index)
  119. {
  120.   if($('item'+lastindex)!=null)setstyle($('item'+lastindex),'d');
  121.   if($('item'+index)!=null)
  122.   {
  123.    setstyle($('item'+index), 'm');
  124.    lastindex=index;
  125.   }
  126.   else $("keyword").focus();
  127. }
  128. function searchclick(index)
  129. {
  130.   $("keyword").value=$('title'+index).innerHTML;
  131.   flag=true;
  132. }
  133. function searchkeydown(e)
  134. {
  135. if($('rlist').innerHTML=='')return;
  136.   var keycode=(window.navigator.appName=="Microsoft Internet Explorer")?event.keyCode:e.which;
  137.   //down
  138.   if(keycode==40)
  139.   {
  140. if(lastindex==-1||lastindex==listlength-1)
  141. {
  142.   focusitem(0);
  143.   searchclick(0);
  144. }
  145. else{
  146.   focusitem(lastindex+1);
  147.   searchclick(lastindex+1);
  148. }
  149.   }
  150. if(keycode==38)
  151. {
  152. if(lastindex==-1)
  153. {
  154.   focusitem(0);
  155.   searchclick(0);
  156. }
  157. else{
  158.   focusitem(lastindex-1);
  159.   searchclick(lastindex-1);
  160. }
  161. }
  162. if(keycode==13)
  163. {
  164.   focusitem(lastindex);
  165.   $("keyword").value=$('title'+lastindex).innerText;
  166. }   
  167. if(keycode==46||keycode==8){flag=false;ajaxsearch($F('keyword').substring(0,$F('keyword').length-1).Trim());}
  168. }
  169. function showresult(xmlhttp)
  170. {
  171. var result=unescape(xmlhttp.responseText);
  172. if(result!=''){
  173.     var resultstring=new StringBuffer();
  174.        var title=result.split('搜索框[code]
  175. <form id="form1" name="form1" method="post" action="">
  176.       <b>输入搜索关键字</b>
  177.     <input name="keyword" type="text" class="inputblue" id="keyword" maxlength="20" style="width:300px;" />
  178. </form>
复制代码
就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[0];
       var hits=result.split('搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6.$hits;?>[/code]js代码[        DISCUZ_CODE_2        ]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[1];
    for(var i=0;i<title.split('|').length;i++)
    {
    resultstring.append('<div id="item'+i+'">');
    resultstring.append('<span id=title'+i+'>');
    resultstring.append(title.split('|'));
    resultstring.append('</span>');
    resultstring.append('<span id=hits'+i+'>');
    resultstring.append(hits.split('|'));
    resultstring.append('</span>');
    resultstring.append('</div>');
    }
    $('rlist').innerHTML=resultstring.tostring();
    for(var j=0;j<title.split('|').length;j++)
    {
     setstyle($('item'+j),'d');
  $('item'+j).displaySpan=$('hits'+j);
     setstyle($('title'+j),'t');
     setstyle($('hits'+j),'h');
    }
    showsearch(title.split('|').length);
    listlength=title.split('|').length;
    lastindex=-1;
}
else hiddensearch();
}
function ajaxsearch(value)
{
new Ajax.Request('search.php',{method:"get",parameters:"action=do&keyword="+escape(value),onComplete:showresult});
}
function main()
{
$('keyword').className=$('keyword').className=='inputblue'?'inputfocus':'inputblue';
if($F('keyword').Trim()=='')hiddensearch();
else
{
      if($F('keyword')!=''&&flag==false)ajaxsearch($F('keyword').Trim());
   if(listlength!=0)$('keyword').onkeydown=searchkeydown;
   else hiddensearch();
}
}
function oninit()
{
$('keyword').autocomplete="off";
$('keyword').onfocus=main;
$('keyword').onkeyup=main;
$('keyword').onblur=hiddensearch;
createlist();
}
Event.observe(window,'load',oninit);
</script>[/code]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6.$hits;?>[/code]js代码[        DISCUZ_CODE_2        ]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[0];
       var hits=result.split('搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[0];
       var hits=result.split('搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6.$hits;?>[/code]js代码[        DISCUZ_CODE_2        ]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[1];
    for(var i=0;i<title.split('|').length;i++)
    {
    resultstring.append('<div id="item'+i+'">');
    resultstring.append('<span id=title'+i+'>');
    resultstring.append(title.split('|'));
    resultstring.append('</span>');
    resultstring.append('<span id=hits'+i+'>');
    resultstring.append(hits.split('|'));
    resultstring.append('</span>');
    resultstring.append('</div>');
    }
    $('rlist').innerHTML=resultstring.tostring();
    for(var j=0;j<title.split('|').length;j++)
    {
     setstyle($('item'+j),'d');
  $('item'+j).displaySpan=$('hits'+j);
     setstyle($('title'+j),'t');
     setstyle($('hits'+j),'h');
    }
    showsearch(title.split('|').length);
    listlength=title.split('|').length;
    lastindex=-1;
}
else hiddensearch();
}
function ajaxsearch(value)
{
new Ajax.Request('search.php',{method:"get",parameters:"action=do&keyword="+escape(value),onComplete:showresult});
}
function main()
{
$('keyword').className=$('keyword').className=='inputblue'?'inputfocus':'inputblue';
if($F('keyword').Trim()=='')hiddensearch();
else
{
      if($F('keyword')!=''&&flag==false)ajaxsearch($F('keyword').Trim());
   if(listlength!=0)$('keyword').onkeydown=searchkeydown;
   else hiddensearch();
}
}
function oninit()
{
$('keyword').autocomplete="off";
$('keyword').onfocus=main;
$('keyword').onkeyup=main;
$('keyword').onblur=hiddensearch;
createlist();
}
Event.observe(window,'load',oninit);
</script>[/code]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6.$hits;?>[/code]js代码[        DISCUZ_CODE_2        ]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[1];
    for(var i=0;i<title.split('|').length;i++)
    {
    resultstring.append('<div id="item'+i+'">');
    resultstring.append('<span id=title'+i+'>');
    resultstring.append(title.split('|'));
    resultstring.append('</span>');
    resultstring.append('<span id=hits'+i+'>');
    resultstring.append(hits.split('|'));
    resultstring.append('</span>');
    resultstring.append('</div>');
    }
    $('rlist').innerHTML=resultstring.tostring();
    for(var j=0;j<title.split('|').length;j++)
    {
     setstyle($('item'+j),'d');
  $('item'+j).displaySpan=$('hits'+j);
     setstyle($('title'+j),'t');
     setstyle($('hits'+j),'h');
    }
    showsearch(title.split('|').length);
    listlength=title.split('|').length;
    lastindex=-1;
}
else hiddensearch();
}
function ajaxsearch(value)
{
new Ajax.Request('search.php',{method:"get",parameters:"action=do&keyword="+escape(value),onComplete:showresult});
}
function main()
{
$('keyword').className=$('keyword').className=='inputblue'?'inputfocus':'inputblue';
if($F('keyword').Trim()=='')hiddensearch();
else
{
      if($F('keyword')!=''&&flag==false)ajaxsearch($F('keyword').Trim());
   if(listlength!=0)$('keyword').onkeydown=searchkeydown;
   else hiddensearch();
}
}
function oninit()
{
$('keyword').autocomplete="off";
$('keyword').onfocus=main;
$('keyword').onkeyup=main;
$('keyword').onblur=hiddensearch;
createlist();
}
Event.observe(window,'load',oninit);
</script>[/code]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[0];
       var hits=result.split('搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6.$hits;?>[/code]js代码[        DISCUZ_CODE_2        ]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6)[1];
    for(var i=0;i<title.split('|').length;i++)
    {
    resultstring.append('<div id="item'+i+'">');
    resultstring.append('<span id=title'+i+'>');
    resultstring.append(title.split('|'));
    resultstring.append('</span>');
    resultstring.append('<span id=hits'+i+'>');
    resultstring.append(hits.split('|'));
    resultstring.append('</span>');
    resultstring.append('</div>');
    }
    $('rlist').innerHTML=resultstring.tostring();
    for(var j=0;j<title.split('|').length;j++)
    {
     setstyle($('item'+j),'d');
  $('item'+j).displaySpan=$('hits'+j);
     setstyle($('title'+j),'t');
     setstyle($('hits'+j),'h');
    }
    showsearch(title.split('|').length);
    listlength=title.split('|').length;
    lastindex=-1;
}
else hiddensearch();
}
function ajaxsearch(value)
{
new Ajax.Request('search.php',{method:"get",parameters:"action=do&keyword="+escape(value),onComplete:showresult});
}
function main()
{
$('keyword').className=$('keyword').className=='inputblue'?'inputfocus':'inputblue';
if($F('keyword').Trim()=='')hiddensearch();
else
{
      if($F('keyword')!=''&&flag==false)ajaxsearch($F('keyword').Trim());
   if(listlength!=0)$('keyword').onkeydown=searchkeydown;
   else hiddensearch();
}
}
function oninit()
{
$('keyword').autocomplete="off";
$('keyword').onfocus=main;
$('keyword').onkeyup=main;
$('keyword').onblur=hiddensearch;
createlist();
}
Event.observe(window,'load',oninit);
</script>[/code]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6.$hits;?>[/code]js代码[        DISCUZ_CODE_2        ]搜索框[        DISCUZ_CODE_3        ]就这些,没加说明,有时间再加吧,加的话 可以去我的博客看看http://www.xqbar.com/read.php?6

[ 本帖最后由 omcmc 于 2009-4-11 15:43 编辑 ]
附件: 您所在的用户组无法下载或查看附件
十分好。赞一个
我心因何恼春风
哎哟,不错的东西..
有注释就更好了..

[ 本帖最后由 小菜鸟 于 2008-1-25 12:42 编辑 ]
prototype库好大。。
2009年,努力、努力再努力! 学习、学习在学习! http://www.bashu51.com/
...顶下
顶一个...

回复 1# 的帖子

支持~~~
PEA重庆联系方式:QQ群:39845061
加入重庆地区PHP人才库,请发短信到 小李 13648305947
返回列表