此功能在原有的基础上增加了table列表的动态刷新显示
jquery.js 版本:1.2.6
下面给出一个简单的例子来说明使用方法
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
[color=YellowGreen]<!-- 引入所需的JS库 -->[/color]
<script type="text/javascript" src="lib/jquery.js"></script>
<script type='text/javascript' src='lib/jquery.bgiframe.min.js'></script>
<script type='text/javascript' src='lib/jquery.ajaxQueue.js'></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="lib/jquery.autocomplete.css" />
</head>
<script type="text/javascript">
[color=YellowGreen]<!-- 制造一个测试用数据 -->[/color]
var websites = [{'id':'1','name':'aaa','pass':'123','age':'10'},{'id':'2','name':'abbb','pass':'321','age':'20'}]
$(function(){
$("#website").autocomplete(websites,
{ minChars: '0',
matchProperty:"name",
[color=YellowGreen] <!--设置显示属性为name pass age-->[/color]
listProperty:["name","pass","age"],
resultProperty:["name"],
idProperty:["id"],
[color=YellowGreen] <!-- 设置name pass age 之间的分割符为 </td><td>
这里必须为"</td><td>"否则页面无法正常显示-->[/color]
showPropertyDelimiter:"</td><td>",
[color=YellowGreen]<!-- 此属性是新增的
如果要使用table必须在页面上写一个div标签,并设置componentId为div标签的id
componentType 设置为table -->[/color]
[color=Red] showComponent:{ componentId:"div1",
componentType:"table"}[/color]
}
);
});
</script>
<body>
<p>
<label>Web Site:</label>
<input type="text" id="website" />
</p>
[color=Red]<div id="div1" >
</div>[/color]
</body>
</html>
autocomplete.js修改内容:
红色部分为修改内容
1. 第120行
}).blur(function() {
hasFocus = 0;
if (!config.mouseDownOnSelect) {
//whether hide 如果显示方式为table则不隐藏结果
[color=Red]if(options.showComponent.componentType!='table'){[/color]
hideResults();
[color=Red]}[/color]
}
2. 第351行
jQuery.Autocompleter.defaults = {
//新增属性
showComponent:{
//获得显示位置标签的ID
componentId:"div",
//获得显示方式 属性值为"ul"或者"table"
componentType:"ul",
//如果显示方式为table那么为其指定CSS
tableClass: "table_results"
},[/color]
......
3.第554行
根据使用table或是ul创建不同的element及list
var element;
var list;
//showComponent is 'table' or 'ul'
if(options.showComponent.componentType=='table'){
element = jQuery("#"+options.showComponent.componentId);
list=jQuery("<table>")
.appendTo(element)
.addClass(options.showComponent.tableClass);
}else if(options.showComponent.componentType=='ul'){[/color]
element = jQuery("<div>")
.hide()
.addClass(options.resultsClass)
.css("position", "absolute")
.appendTo("body");
list = jQuery("<ul>").appendTo(element).mouseover( function(event) {
if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI')
{
active = jQuery("li", list).removeClass().index(target(event));
jQuery(target(event)).addClass(CLASSES.ACTIVE);
}
}).mouseout( function(event) {
// why we must to do that? is it really needed ?
/*jQuery(target(event)).removeClass();*/
return;
}).click(function(event) {
jQuery(target(event)).addClass(CLASSES.ACTIVE);
select();
input.focus();
return false;
}).mousedown(function() {
config.mouseDownOnSelect = true;
}).mouseup(function() {
config.mouseDownOnSelect = false;
});
}
......
第662行 fillList()方法
根据显示方式为table或ul对生成对应的数据
function fillList() {
list.empty();
//showComponent is 'table'
[color=Red] if(options.showComponent.componentType=='table'){
var tr = jQuery("<tr>");
var title = options.listProperty;
title = title.toString(title).split(",");
for(var j=0;j<title.length;j++){
tr.append("<td>"+title[j]+"</td>");
}
tr.appendTo(list);
}[/color]
var num = limitNumberOfItems(data.length);
for (var i=0; i < num; i++) {
if (!data[i])
continue;
var formatted = options.formatItem ? options.formatItem(data[i].data, i+1, num, data[i].value) : defaultFormatItem(data[i].data,i+1, num);
if ( formatted === false )
continue;
//showComponent is 'table' or 'ul'
[color=Red] if(options.showComponent.componentType=='table'){[/color]
jQuery("<tr>").html( "<td>"+options.highlight(formatted, term)+"</td>" ).appendTo(list)[0].index = i ;
[color=Red]} [/color]
[color=Red]else if(options.showComponent.componentType=='ul'){[/color]
jQuery("<li>").html( options.highlight(formatted, term) ).appendTo(list)[0].index = i;
[color=Red]}[/color]
}
//showComponent is 'table' or 'ul'
[color=Red]if(options.showComponent.componentType=='table'){[/color]
listItems = list.find("tr");
[color=Red]}else if(options.showComponent.componentType=='ul'){[/color]
listItems = list.find("li");
[color=Red]}[/color]
if ( options.selectFirst ) {
//showComponent is 'ul'
[color=Red]if(options.showComponent.componentType=='ul'){[/color]
listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
active = 0;
[color=Red]}[/color]
}
if( options.moreItems.length > 0 && !options.scroll) moreItems.css("display", (data.length > num)? "block" : "none");
list.bgiframe();
}
分享到:
相关推荐
jquery autocomplete下载.rar
Jquery AutoComplete
JQuery autocomplete ajax分页,对源码稍微修改了下
在输入页面利用JQuery获取用户输入,然后通过AJAX异步发送到处理页面,...若是jquery autoComplete组件则只要将从后台获取的数据放入autocomplete( url or data, [options] )第一个参数中就行,第二个参数可加可不加。
jquery.autocomplete.js 、jquery.autocomplete.css
jquery autocomplete 动态补全例子支持中文 ajax传递json数据 文件里有json数据拼接
jquery-autocomplete搜索框自动完成的中文文档,上手快,轻便,功能强大
Jquery autocomplete插件使用
jQuery Autocomplete,百度搜索框提示效果。
jquery autocomplete.js 是一款优秀的开源JS,支持自动完成,不过如果是中文失效。原因是由于中文编码不一致引起的,修改源文件中AJAX请求中的编码,加上escape编码后,在后台用Server.URLDecode解码后,则中文也...
jquery-autocomplete 可用
jquery autocomplete 所需js文件及样式。 实现仿百度输入查询下拉功能。
jQuery plugin: Autocomplete 参数及实例 官网:jQuery plugin: Autocomplete 此插件依赖于 jquery 1.2.6 --- jquery 1.8.3 转自:http://www.cnblogs.com/duanhuajian/p/3398904.html
使用Jquery AutoComplete 插件来做自动填充功能,包含本地数组,后台数据等情况
NULL 博文链接:https://zhaoaiqing.iteye.com/blog/333869
jquery autocomplete官方版(源代码+示例) 自动补充功能非常实用
jquery自动补全插件(jquery autocomplete) 内包含使用说明,前台+后台
jQuery autocomplete 自动加载
NULL 博文链接:https://bask.iteye.com/blog/766441
jQuery Autocomplete plugin是在jQuery的基础上开发的一套小巧的输入下拉提示插件,这是它的PHP应用实例,大部分功能与HTML格式网页类同,这里增加了一些需要PHp程序配合的内容,它不但有输入提示功能,而且示例本身...