github地址:https://github.com/tianxiangbing/autosearch
demo地址:http://www.lovewebgames.com/jsmodule/autosearch.html
静态数据:var input = $('.autosearch0'); var autosearch = new AutoSearch(); var data = [{adminid:1,adminname:"javascript"},{adminid:2,adminname:"java"}]; autosearch.init({input:input,autoShow:true,data:data,valueObj:'#hd_id0',filterColumn:['adminname'],column:['adminname'],valueName:"adminid"});静态数据,回车动态添加项:
var input = $('.autosearch1'); var autosearch = new AutoSearch(); var data = [{key:"javascript"},{key:"java"}]; autosearch.init({ input:input,autoShow:true,data:data,valueObj:'#hd_id1', filterColumn:['key'],column:['key'],valueName:"key", enterCallback:function(input){ var value = $(input).val(); $(input).attr('data-text',value) data.push({key:value}); },callback:function(){ } });ajax请求:
$.get('data.txt',function(result){ var input = $('.autosearch'); var autosearch = new AutoSearch(); autosearch.init({input:input,autoShow:true,data:result,valueObj:'#hd_id',valueName:"id"}); },'json')ajax请求:
var input = $('.autosearch2'); var autosearch = new AutoSearch(); autosearch.init({input:input ,autoShow:false,data:function(callback){ $.get('data.txt',{key:input.val()},function(result){ callback(result); },'json'); } });多选:
$.get('data.txt',function(result){ var input = $('.autosearch3'); var autosearch = new AutoSearch(); autosearch.init({input:input,autoShow:false,data:result,mutil:true }); },'json')