很酷的一個自動補全插件
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 主站蜘蛛池模板: 黎川县| 灵宝市| 平山县| 松江区| 墨竹工卡县| 穆棱市| 井陉县| 镇平县| 盐津县| 花莲市| 永春县| 牡丹江市| 齐河县| 平乐县| 佛坪县| 桐梓县| 鲁山县| 大石桥市| 黎城县| 元阳县| 黑山县| 息烽县| 佛教| 界首市| 会宁县| 荆州市| 佛山市| 武清区| 河北区| 古浪县| 旺苍县| 电白县| 长宁区| 博野县| 石阡县| 焉耆| 栖霞市| 米泉市| 宁陵县| 当雄县| 澄江县|