好程序就是懶人喜歡的程序。好程序員就是懶人程序員。昨天研究了一下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> 
復制代碼 代碼如下:
 
<div> 
<h4> 模仿BaiDu,google搜索提示功能</h4> 
<table> 
<tr><td>名稱:<input type="text" /></td></tr> 
</table> 
</div> 
新聞熱點
疑難解答
圖片精選