仿百度搜索下拉框Select

自己写了一个input模糊匹配(仿百度)分享给大家,使用简单,兼容很多js框架

参照select2、autocomplete

config = {
		       /*
		        * type : Number [可选]

		        * width:下拉框的宽度,默认使用输入框宽度
		        */
	               width:$this.outerWidth() - 2,
	               /*
	                * type: Array 
	                * url和data参数只有一个生效,data优先
	                */
	               data:null,
	               /*
	                * type : String
	                * url:格式url:""用来ajax后台获取数据,返回的数据格式为data参数一样
	                * (自动取输入框的值,keyword:value) 
	                */
	               url:null,
	               /*
	                * type : Boolean [可选]
	                * 用户是否可以自定义值(false后只能单击或Enter能选中值)
	                * =false时 清空全部值会调用callback方法 (null,param)
	                */
	               custom:true,
	               /*
	                * type : Function [可选]
	                * 下拉框行格式化 
	                * params[(data,index,row)]
	                */
	               formatItem:null,
	               /*
	                * type : Function [可选]
	                * 选中后输入框显示值 default : formatItem
	                * params[(data,index,row)]
	                */
	               formatSelected:null,
	               /*
	                * type : String [可选]
	                * default : title
	                * 格式化输出后,选中值
	                */
	               title:'title',
	               /*
	                * type : Function [可选]
	                * callback:选中行后按回车或单击时回调的函数
	                * params[(row,param)]
	                */
	               callback:null,
	               /*
	                * [可选]
	                * callback方法的第二个参数,用于自定义值
	                */
	               param:null,
}

在线演示 | 在线下载

猜你喜欢

转载自blog.csdn.net/qq_36120267/article/details/81251800
今日推荐