欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實現(xiàn)模擬搜索引擎的智能提示功能簡單示例

 更新時間:2019年01月27日 11:53:50   作者:貓屎不是咖啡  
這篇文章主要介紹了jQuery實現(xiàn)模擬搜索引擎的智能提示功能,結(jié)合實例形式分析了jQuery基于事件響應(yīng)及頁面元素屬性動態(tài)操作實現(xiàn)的模擬搜索提示相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了jQuery實現(xiàn)模擬搜索引擎的智能提示功能。分享給大家供大家參考,具體如下:

jQuery中模仿搜索引擎的智能提示功能,本案例僅供初學(xué)者一個參考,也是我個人在初學(xué)jquery時寫的一個初學(xué)案例。有不當之處,敬請指教。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>www.dbjr.com.cn jQuery模擬搜索提示</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
    var arr=['小李','小二','小三','老林','老王','二哈','小強'];
      var focus=false;
      $(document).ready(function(){
        $("#txt").bind("focus",function(){
          $("#auto").show();
          abc();
        });
        $("#txt").bind("keyup",function(){
          abc();
        });
        $("#txt").bind("blur",function(){
          $("#auto").hide();
        });
        function abc(){
          var auto=$("#auto");
          var txt=$("#txt").val();
          var new_arr=new Array();
          var n=0;
          for(i in arr){
            if(arr[i].indexOf($("#txt").val())>=0){
              new_arr[n++]=arr[i];
            }
          }
          auto.empty();
          for(i in new_arr){
            var DivNode=$("<div>").attr("id",i);
            DivNode.attr("style","width:100px;height:30px;border: 1px solid red;");
            DivNode.mouseover(function(){
              $(this).css("background-color","white");
            });
            DivNode.mouseleave(function(){
              $(this).css("background-color","white");
            });
            DivNode.click(function(){
              $("#txt").val($(this).html());
            });
            DivNode.html(new_arr[i]);
            auto.append(DivNode);
          }
        }
      });
    </script>
  </head>
  <body>
    <div>
    <input type="text" id="txt"/>
    <div id="auto"></div>
    </div>
  </body>
</html>

運行效果:

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun測試上述代碼運行效果。

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery擴展技巧總結(jié)》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論