Ключевой код заключается в следующем:
$ ('#Sale'). Typeahead ({ajax: {url: '@url.action ("../ Contract/getsale")', // Timeout: 300, Метод: 'post', TriggerLength: 1, CloadingClass: Null, Preprocess: Function (Result) {return Result;}, Value: "Value:" ID: элементы, элементы, элементы, элементы, элементы, элементы, элементы, элементы, элементы: valcected: valcected: valcected: valcepticted: valcepticted: {$ ("#SalesId"). Val (val);}});Это автоматическое завершение Typeaide не является TypeaHead.js, обычно используемым в начальной загрузке. Ниже приведен код typeahead.js (лучше, если есть Bootstrap3-typeahead.js)
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Bootstrap Plugin // http://twitter.github.com/bootstrap/javascript.html#typeahead///////mest // ---------------- // jQuery 1.7+// Twitter Bootstrap 2.0+////////////m --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {this. $ element = $ (element); this.Options = $ .extend (true, {}, $. this.eventsupported; this.grepper = this.options.grepper || this.grepper; this.highlighter = this.options.highlighter || this.highlighter; this.lookup = this.options.lookup || this.lookup; this.matcher = this.options.matcher || this.matcher; this.render = this.options.render || this.render; this.select = this.options.select || this.sorter = this.options.sorter || this.sorter; this.source = this.options.source || this.source; if (! this.source.length) {var ajax = this.options.ajax; if (typeof ajax === 'string') {this.ajax = $ .extend ({}, $. $. Typeahead, // ====================================================================== ============================================================================ Utils //// =============================================================== ======================================================================= ================================================================ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1.8 // EventsUpported: function (eventName) {var isSupported = (eventName в этом. $ Element); if (! Issupported) {this. $ Element.setattribut issupported;}, // =================================================================== ============================================================================ Ajax //// ================================================================ ======================================================================= ========================/---------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. это;} // Query изменил nathat.query = Query; // Отмена последнего таймера, если setif (that.ajax.timerid) {cleartimeout (that.ajax.timerid); that.ajax.timerid = null;} if (! Query || Query.length <that.ajax.triggerlength) {// Отмена обратного вызова ajax, если в progressif (that.ajax.xhr) {that.ajax.xhr.abort (); that.ajax.xhr = null; that.ajaxtoggleloadclass (false);} вернуть это. Шоун? that.hide (): that;} // Query хорошо отправить, установите timerth.ajax.timerid = settimeout (function () {$ .proxy (that.ajaxexecute (Query), that)}, that.ajax.timeout); that;},//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (query) {this.ajaxtoggleloadclass (true); // Отмена последнего вызова, если уже находится в прогрессе (this.ajax.xhr) this.ajax.xhr.abort (); var params = this.ajax.predispatch? this.ajax.predispatch (Query): {Query: Query}; var jajax = (this.ajax.method === "post")? $ .post: $ .get; this.ajax.xhr = jajax (this.ajax.url, params, $ .proxy (this.ajaxlookup, this)); this.ajax.timerid = нулевой;},//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- retreivalThis.ajax.data = data; items = this.grepper (this.ajax.data); if (! items ||! item.length) {return this.shown? this.hide (): this;} this.ajax.xhr = null; вернуть this.render (item.slice (0, this.options.items)).show();},//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ (! this.ajax.loadingclass) return; this. $ element.toggleclass (this.ajax.loadingclass, Enable);}, // =================================================================================================== ========================================================================================= Данные Манипуляция //// ============================================================================ ======================================================================= ==================================================================== ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. что. $ element.val (); if (! that.query) {вернуть это. that.hide (): that;} items = that.grepper (that.source); if (! itse ||! item.length) {вернуть это. that.hide (): that;} вернуть это. that.options.items)).show();}},//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- это = это, элементы; if (data && data.length &&! data [0] .hashownproperty (that.options.display)) {return null;} ements = $ .grep (data, function (item) {return that.mather (item.options.display], item);}; this.sorter(items);},//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ~item.toLowerCase().indexOf(this.query.toLowerCase());},//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {beginswith.push (item);} else if (~ item [that.options.display] .indexof (this.query)) {caseensitive.push (item);} els Казеонезивный);}, // ===================================================================================== ================================================================================== Дом Манипуляция //// ============================================================================ ======================================================================= ====================================================================== ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. это. $ element [0] .offsetheight}); this. $ menu.css ({top: pos.top + pos.height, слева: pos.left}); this. $ menu.show (); this.shown = true; return; this;},//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Highlights Матч (ES) в результатах // Highlighter: function (item) {var Query = this.query.replace (/^/-/nmymbersismathment. '</strong>';});},//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- list//render: function (элементы) {var that = this; items = $ (items) .map (function (i, item) {i = $ (that.options.item) .attr ('value', item [that.options.val]); i.find ('a'). html (that highlighter (item.options.display], элемент)); i [0];}); item.first (). addClass ('active'); this. $ menu.html (items); return этот;},//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- this.hide ();}, // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. Выбирает предыдущий результат // prev: function (event) {var active = this. $ Menu.find ('. Active'). Removeclass ('active'); var prev = active.prev (); if (! Prev.length) {prev = this. $ menu.find ('li'). Last ();} prev.addclass ('active');}, // =================================================================================================== ======================================================================== ======================================================================= События //// ================================================================ ======================================================================= =============================================================== ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- этот)); if (this.eventsupported ('keydown')) {this. $ element.on ('keydown', $ .proxy (this.keypress, this));} else {this. $ element.on ('keypress', $ .proxy (this.keypress, это)); 'li', $ .proxy (this.mouseenter, this));},//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- being raised up//keyup: function (e) {e.stoppropagation (); e.preventdefault (); switch (e.keycode) {case 40: // Down Arrowcase 38: // up Arrowbreak; case 9: // tabcase 13: // enterif (! this.shown) {return;} this.select (); Break; случаи 27: // escapethis.hide();break;default:this.lookup();}},//--------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Нажатие // keypress: function (e) {e.stoppropagation (); if (! this.shown) {return;} switch (e.keycode) {case 9: // tabcase 13: // entercase 27: // escapee.preventdefault (); break; case 38: // urrowe.preventdefault (); arrowe.preventDefault();this.next();break;}},//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Руководители нажатия по списку результатов // Нажмите: Функция (e) {e.stopPropagation();e.preventDefault();this.select();},//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. {this.$menu.find('.active').removeClass('active');$(e.currentTarget).addClass('active');}}//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {$ this.data ('typeahead', (data = new typeahead (this, options)));} if (typeof option === 'string') {data[option]();}});}//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- }, ajax: {url: null, timeout: 300, метод: 'post', triggerlength: 3, cloadingclass: null, displayfield: null, predispatch: null, preprocess: null}} $. Typeahead;//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- $ ('body'). Off ('. Data-Api') // Дополнительная информация здесь: https://github.com/twitter/bootstrap/tree/master/js//$(function () {$ ('body'). On ('Focus.typeahead.data-Api', '[data-provide = "typeaeade', vareshead; ($ this.data ('typeahead')) {return;} e.preventdefault (); $ this.typeahead ($ this.data ());})});} (window.jquery);Выше приведено пример подключаемого заполнения Bootstrap Automatic Applysion Plug-In, представленный вам редактором. Я надеюсь, что это будет полезно для вас. Если у вас есть какие -либо вопросы, пожалуйста, оставьте мне сообщение, и редактор ответит вам вовремя. Большое спасибо за вашу поддержку сайту wulin.com!