当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Jquery模仿Baidu、Google搜索时自动补充搜索结果提示

Jquery模仿Baidu、Google搜索时自动补充搜索结果提示

2019年03月20日  | 移动技术网IT编程  | 我要评论

好程序就是懒人喜欢的程序。好程序员就是懒人程序员。昨天研究了一下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>



. 代码如下:


<p>
<h4> 模仿baidu,google搜索提示功能</h4>
<table>
<tr><td>名称:<input type="text" id="keyword" /></td></tr>
</table>
</p>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网