(079)jquery_插件_autocomplete

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title>plug_autocomplete.html</title>
    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    <link rel="stylesheet" type="text/css" href="../css/jquery_autocomplete/jquery.autocomplete.css"></link>
    <style type="text/css">
        #divtest
        {
            width: 282px;
        }
        #divtest .title
        {
            padding: 8px;
            background-color: Blue;
            color: #fff;
            height: 23px;
            line-height: 23px;
            font-size: 15px;
            font-weight: bold;
        }
        #divtest .content
        {
            padding: 8px 0px;
            background-color: #fff;
            font-size: 13px;
        }
        #divtest .content .tip
        {
            text-align:center;
            border:solid 1px #ccc;
            background-color:#eee;
            margin:20px 0px;
            padding:8px;
            display:none;
        }
        .fl
        {
            float: left;
        }
        .fr
        {
            float: right;
        }
    </style>
    <script type="text/javascript" src="../js/jquery/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="../js/jquery_autocomplete/jquery.autocomplete.js"></script>
    <script type="text/javascript">
        $(function(){
            var userArray = ["用户1","用户2","用户3","用户4","用户5"];
            $("#txtSearch").autocomplete(userArray,{
                minChars:0, //双击空白文本框时显示全部提示数据
                formatItem:function(data,i,total){ //改变匹配的数据显示格式
                    return "<i>" + data[0] + "</i>";
                },
                formatMatch:function(data,i,total){
                    return data[0];
                },
                formatResult:function(data,i,total){
                    return data[0];
                }
            }).result(function(event,data,formatted){
                $(".tip").show().html(data?formatted:"");
            });
        });
    </script>
  </head>
  
  <body>
        <div id="divtest">
            <div class="title">
                <span class="fl">搜索插件</span>
            </div>
            <div class="content">
                <span class="fl">用户名</span><br />
                <input id="txtSearch" name="txtSearch" type="text" />
                <div class="tip">
                </div>
            </div>
        </div>
  </body>
</html>

 

posted @ 2015-01-07 17:32  雪中飞雁  阅读(73)  评论(0)    收藏  举报