Jquery 模仿Baidu、Google收索時提示輸入結果

好程序就是懶人喜歡的程序。好程序員就是懶人程序員。昨天研究了一下Jquery 模仿Baidu、Google收索時自動補充收索結果的提示,感覺效果還行。特意和大家分享一下。所需Jquery插件。請看代碼:

<script type="text/javascript">
$().ready( function () {

$(":text").result(auto);
 
        function auto(data){
$("#keyWord").val(data.name);
}

        $("#keyWord").autocomplete(obj, {//obj是數據對象數組Json
            minChars: 0, //表示在自動完成激活之前填入的最小字符
            max: 5, //表示列表裏的條目數
            autoFill: true, //表示自動填充
            mustMatch: false, //表示必須匹配條目,文本框裏輸入的內容,必須是data參數裏的數據,如果不匹配,文本框就被清空
            matchContains: true, //表示包含匹配,相當於模糊匹配
            scrollHeight: 200, //表示列表顯示高度,默認高度爲180


            formatItem: function (row) {
                return row.name;
            },
            formatMatch: function (row) {
                return row.name;
            },
            formatResult: function (row) {
                return row.value;
            }
        });
    });
</script>

jsp:

<div>
    <h4> 模仿BaiDu,google搜索提示功能</h4>
        <table>
        <tr><td>名稱:<input type="text" id="keyWord" /></td></tr>
        </table>
    </div>

注:此demo並非原創。意在傳播。方便大家。demo:http://download.csdn.net/detail/cs19920/6771343

發佈了25 篇原創文章 · 獲贊 1 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章