php + jQuery自动完成插件autocompleter
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
php + jQuery自动完成插件autocompleter的更多相关文章
- jQuery自动完成插件flexselect
项目中使用flexselect自动完成插件时遇到一个问题 刚开始以为是js的引用顺序有问题,但是查看后发现不是js引用顺序问题 js引用顺序如下 最后查找资料也没有解决问题,一直提示这个错误 后来在f ...
- jquery自动完成插件的使用
.ui-autocomplete { z-index: !important; max-height: 100px; overflow-y: auto; /* 防止水平滚动条 */ overflow- ...
- 30+最佳Ajax jQuery的自动完成插件的例子
在这篇文章中,我们将介绍35个jQuery AJAX的自动完成提示例子. jQuery 的自动完成功能,使用户快速找到并选择一定的价值.每个人都想要快速和即时搜索输入栏位,因为这个原因,许 流行的搜索 ...
- jQuery 自动完成文本框
jQuery自动完成插件开源软件 http://www.oschina.net/project/tag/329/jquery-autocomplete jQuery TextExt http://te ...
- jQuery图片自动添加水印插件
JS脚本(jQuery)为图片加水印效果预览:http://hovertree.com/texiao/jquery/94/ 本功能使用HTML5实现,可为图片加上文字水印,可设置文字,设置颜色,位置等 ...
- 弹窗中使用jquery ui的autocomplete自动完成插件无效果 实际是被遮挡了
在普通页面上使用jquery ui的autocomplete自动完成插件时正常显示提供选择的下拉框,但是放到弹窗中的时候就无法显示这个选择的下拉框,其它效果正常: 估计是被弹出窗遮挡了,网络搜索了jq ...
- jQuery框架学习第十一天:实战jQuery表单验证及jQuery自动完成提示插件
jQuery框架学习第一天:开始认识jQueryjQuery框架学习第二天:jQuery中万能的选择器jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQuer ...
- jquery.autocomplete.js 插件的自定义搜索规则
这二天开始用jquery.autocomplete这个自动完成插件.功能基本比较强大,但自己在实际需求中发现还是有一处不足!问题是这样:当我定义了一个本地数据JS文件时,格式为JSON式的数组.如下: ...
- 提升用户体验的最佳免费 jQuery 表单插件
网页表单是一个老生常谈的话题.出于这样或那样的目的,一些示例中都会包括用户注册,电子商务结算,用户设置甚至联系人表格.而输入栏是非常容易用现代的CSS3技术来应用样式.但是到底什么决定整体用户体验? ...
随机推荐
- springmvc HandlerInterceptoer WebRequestInterceptor MethodInterceptor使用
HandlerInterceptoer拦截的是请求地址,所以针对请求地址做一些验证.预处理等操作比较合适.
- DS实验题 融合软泥怪-2 Heap实现
题目和STL实现:DS实验题 融合软泥怪-1 用堆实现优先队列 引言和堆的介绍摘自:Priority Queue(Heaps)--优先队列(堆) 引言: 优先队列是一个至少能够提供插入(Insert) ...
- Bootstrap响应式栅格系统的设计原理
1.历史背景 Bootstrap是Twitter的工程师Mark Otto和Jacob Thornton开发的一套供内部使用的UI框架,于2011年开源.2012年发布的第二版中新增了12列栅格系统和 ...
- java 性能优化(代码优化)
参考博文: java 性能优化:35 个小细节,让你提升 java 代码的运行效率
- netfiler源代码分析之框架介绍
netfiler框架是在内核协议栈实现的基础上完成的,在报文从网口接收,路由等方法实现基础上使用NF_HOOK调用相应的钩子来进入netfiler框架的处理,如 ip_rcv之后会调用NF_HOOK( ...
- HTML中添加背景音乐
<audio controls="controls" height="100" width="100"> <source ...
- http 状态码
一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 详细分解: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 ...
- new一張form時用using{}的好處。
以下代碼,用Using可避免一些問題,例如handel10000.如果PaymentForm裏面用dialogresult=''而不是close或X,(close或X會即時dispose回收,但dia ...
- c语言1
1.c语言的执行过程: 源代码:source code,使用某种计算机语言书写的代码. 编译:compile 对源代码进行翻译的过程. 编译器:compiler 负责编译工具. gcc:一款通用的编译 ...
- List转换成XML
protected void Button1_Click(object sender, EventArgs e) { var customerlist = CustomerHelper.GetList ...