很酷的一個自動補全插件
http://twitter.github.io/typeahead.js
在bootstrap中使用typeahead插件,完成自動補全
相關的文檔:https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md
數據源:
Local:數組
prefectch:json
remote等方式
--------------------------------------------------------------------------------

html:
<input id="orderNo" class="typeahead" placeholder="Countries" type="text" class="form-control" name="ordersn">
js:
var states = new Bloodhound({datumTokenizer: Bloodhound.tokenizers.whitespace,queryTokenizer: Bloodhound.tokenizers.whitespace,// `states` is an array of state names defined in "The Basics"local: states});var findOrderByIdVague = new Bloodhound({datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),queryTokenizer: Bloodhound.tokenizers.whitespace,prefetch: '${ctx}/admin/order/preOrderByIdVague.json',remote: {url: '${ctx}/admin/order/findOrderByIdVague/%QUERY.json',wildcard: '%QUERY'},afterSelect: function (item) {//選擇項之后的事件 ,item是當前選中的。alert(iterm);}});$(function(){/**$('#addCombo .typeahead').typeahead({hint: true,highlight: true,minLength: 1},{name: 'states',source: states});**/$('#addCombo .typeahead').typeahead(null, {name: 'best-pictures',display: 'value',source: findOrderByIdVague});$('#addCombo .typeahead').bind('typeahead:select', function(ev, suggestion) {console.log('Selection: ' + suggestion.value);});}); …findOrderByIdVague/D20150502.json:[ {"value" : "D20150502173435141299"}, {"value" : "D20150502172928109304"} ] preOrderByIdVague.json:
[{"value":"D201"}] docs 相關的事件:
Custom EventsThe following events get triggered on the input element during the life-cycle of a typeahead.typeahead:active 主站蜘蛛池模板: 西乌| 伊春市| 喀喇沁旗| 武汉市| 博白县| 宁乡县| 搜索| 裕民县| 潼关县| 汕尾市| 杭锦后旗| 同仁县| 阿拉尔市| 融水| 徐闻县| 成都市| 金阳县| 甘孜县| 大邑县| 繁昌县| 凤山市| 墨脱县| 孟津县| 佛教| 治县。| 万州区| 泰宁县| 巧家县| 秦安县| 桐乡市| 临颍县| 贵州省| 夏邑县| 驻马店市| 泉州市| 潞西市| 定陶县| 临安市| 板桥市| 赤水市| 景德镇市|