输入联想智能补全插件

Autocomplete.js


github:https://github.com/agarzola/jQueryAutocompletePlugin


	var data = "the People's Republic of China".split(" ");
	$("#autocomplete").autocomplete(data,{minChars:0}).result(function(event,data,formatted){
		alert(data);
	});

	var emails = [
            { inventory: "10", fabric: "AFDFDF" },
            { inventory: "234", fabric: "FGFG" },
            { inventory: "2", fabric: "JHJHJ" },
            { inventory: "3", fabric: "XCVCXV" },
            { inventory: "565", fabric: "HGHFGH" },
            { inventory: "6", fabric: "HGHGHG" },
            { inventory: "7", fabric: "FGDFGH" },
            { inventory: "77", fabric: "SDFFGFG" },
            { inventory: "34", fabric: "DFGDSFG" },
            { inventory: "65", fabric: "JYHJGHJ" },
            { inventory: "2", fabric: "GDFGDFG" },
            { inventory: "56", fabric: "GFHFGH" }
        ];
		
	$("#autocomplete2").autocomplete(emails,{
              minChars: 0,//自动完成激活之前填入的最小字符
              max:12,//列表条目数
              width: 150,//提示的宽度
              scrollHeight: 200,//提示的高度
              matchContains: true,//是否只要包含文本框里的就可以
              autoFill:false,//自动填充
              formatItem: function(data, i, max) {//格式化列表中的条目 row:条目对象,i:当前条目数,max:总条目数
return data.inventory+ '[' + data.fabric + ']';
            },

            formatResult: function(data) {//定义最终返回的数据,比如我们还是要返回原始数据,而不是formatItem过的数据
return data.fabric;
            }
        }).result(function(event,data,formatted){
            alert('库存为'+data.inventory);
        });
		
	
});

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>