autocompleter是一个简单的,容易的,可定制的自动完成功能插件,支持缓存。

1、引用脚本

<script type="text/javascript" src="./jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="./jquery.autocompleter.js"></script>

2、添加样式

/**
* 自动提示样式 Simplecomplete
*/
.autocompleter {
width: 100%;
background: #E1E7ED;
top: 35px;
left:;
z-index:;
border-radius: 5px;
} .autocompleter,
.autocompleter-hint {
position: absolute;
} .autocompleter-list {
box-shadow: inset 0px 0px 6px rgba(0,0,0,0.1);
list-style: none;
text-align: left;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-radius: 9px; }
.autocompleter-list>li {
padding-left:19px;
line-height: 38px;
border-radius: 9px;
} .autocompleter-item-selected {
background: #ffffff;
} .autocompleter-item {
padding: 6px 12px;
color: #444444;
font-size: 15px;
cursor: pointer;
} .autocompleter-item:hover {
background: grey;
} .autocompleter-item strong {
background: #f9de8f;
text-shadow: 0 1px 0 #ffffff;
} .autocompleter-item span {
color: #bbbbbb;
} .autocompleter-hint {
color: #ccc;
text-align: left;
top: -56px;
font-weight:;
left:;
width: 100%;
padding: 12px 12px 12px 13px;
font-size: 24px;
display: none;
} .autocompleter-hint span {
color: transparent;
} .autocompleter-hint-show {
display: block;
} .autocompleter-closed {
display: none;
}

也可以引用 jquery.autocompleter.css ,作相应处理;

3、定义你的autocompleter:

$(function () {
$('input').autocompleter({ source: 'path/to/get_data_request' });
});

或用于本地JSON来源:

var data = [
{ "value": "1", "label": "one" },
{ "value": "2", "label": "two" },
{ "value": "3", "label": "three" }
];
$(function () {
$('input').autocompleter({ source: data });
});

4、完整代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>冷暖自知一抹茶ck</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//cdn.bootcss.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="./css/global.css"> <script type="text/javascript" src="./jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="./jquery.autocompleter.js"></script>
</head>
<body>
<div class="nav">
123456789
</div>
<div class="search">
<div class="search_text" style="">
<input id="searchtxt" class="bantxt" name="searchtxt" placeholder="搜索关键字.." style="border: 1px solid rgb(44, 44, 44);" maxlength="60" type="text" />
<button id="seobut" class="btn banbutt" type="button">
<i class="fa fa-search"></i>
</button>
</div>
</div>
<script>
$(function () {
$('#searchtxt').autocompleter({
highlightMatches: true, // marker for autocomplete matches
source: "server.php", // object to local or url to remote search template: '{{ label }} <span>({{ id }})</span>', // custom template
//template: '<span id="{{ id }}">{{ label }}</span>', empty: false, // abort source if empty field[如果数据为空,阻止检索]
limit: 10, // max results[最多查询显示条数]
cache: true,
callback: function (value, index, selected) {
if (selected) {
//$('.icon').css('background-color', selected.hex);
$('#searchtxt').attr("data-value",selected.id);
}
}
}); $("#seobut").click(function() {
var seo = $("#searchtxt").val();
if (seo.length > 1) {
window.location.href = "search?seo=" + seo;
}
});
$('#searchtxt').bind('keypress',
function(event) { if (event.keyCode == "13") {
var seo = $("#searchtxt").val();
if (seo.length > 1) {
window.location.href = "search?seo=" + seo;
}
}
}); });
</script>
<div class="container" style="width:100%;height:auto;">
<div style="width:1050px;height:auto;margin:0 auto;">
<div style="width:60%;height:900px;background:yellow;float:left;margin:2%;padding:2% 1%;">
<div style="">123456</div>
<div style="">789456</div>
</div>
<div style="width:26%;height:900px;background:pink;float:right;margin-left:6%;margin:2%;padding:2% 1%">
<div style="">123456</div>
<div style="">789456</div>
</div>
<div style="clear:both;"></div>
</div>
</div> <div style="width:100%;text-align:center;">
<p>冷暖自知一抹茶ck</p>
</div>
</body>
</html>

参考资料:https://github.com/ArtemFitiskin/jquery-autocompleter

打包文件:链接:http://pan.baidu.com/s/1o8Ivgtc 密码:ivc7

最新文章

  1. 使用ASP.NET Web API Help Pages 创建在线接口文档
  2. Java多线程系列--“JUC集合”05之 ConcurrentSkipListMap
  3. 使用CallerMemberName简化InotifyPropertyChanged的实现
  4. t-sql中字符串前加N代表什么意思
  5. sql server多表数据批量更新
  6. JavaScript 文件上传类型判断
  7. 8种方法提升windows 8使用方便-----Win+x 编辑菜单
  8. JAVA 正则表达式 (超详细)
  9. #include &lt;iomanip&gt;
  10. 自适应Cell
  11. Mybatis(二)参数(Parameters)传递
  12. nodejs----微信注册测试号获取token
  13. windows red5相关
  14. Vi编辑器中全局替换
  15. Yii框架实现restful 接口调用,增删改查
  16. 【AtCoder】CODE FESTIVAL 2017 qual A
  17. computed 计算选项
  18. [转]改善C#程序的建议4:C#中标准Dispose模式的实现
  19. 20135202闫佳歆--week1 计算机是如何工作的
  20. MFC onchar()

热门文章

  1. spring mvc controller间跳转 重定向 传参 (转)
  2. 【Demo】QQ,github,微博第三方社交登录
  3. vert.x学习(一),开篇之hello world
  4. sprint2总结
  5. cloudera learning7:Hadoop资源管理
  6. Magento table rates表运费设置
  7. System.Web.AspNetHostingPermission 类型的权限已失败
  8. opencv,图片遍历
  9. 多线程java的concurrent用法详解(转载)
  10. NODEJS 在Centos下面的自动启动