Kode kuncinya adalah sebagai berikut:
$ ('#Sale'). Typeahead ({Ajax: {url: '@url.action ("../ Contract/getsale")', // Timeout: 300, Metode: 'Post', TriggerLength: 1, LoadingClass: Null, Preprocess: Fungsi (Hasil) {Return Hasil;}}, tampilan: "Vale", Vale ", Vale", ID "ID", Fungsi: ID: IT: ID: ID: IT: IT: ITS: AFFICT: IT FUCT: ITSECES: ITSICES: FUNCTER: IT FUCTECESS: FUNCTER: IT FUCTECESS: FUNCTER: I. {$ ("#SalesID"). Val (val);}});Penyelesaian otomatis TypeaHead ini bukan typeahead.js yang biasa digunakan dalam bootstrap. Di bawah ini adalah kode typeahead.js (lebih baik jika ada bootstrap3-typeead.js)
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Bootstrap Plugin Typeahead // http://twitter.github.com/bootstrap/javascript.html#typeahead//////// --------------- // JQuery 1.7+// Twitter Bootstrap 2.0+// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (element, options) {this. $ element = $ (element); this.options = $ .extend (true, {}, $ .fn.typeAhead.defaults, opsi); this. $ menu = $ (this.options.menu). lampo ('body'); this.shown = false; // metode ini mengungguli ini.eventsupported ('body'); this.shown = false;/ Metode mengungguli ini. 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 ({}, $ .fn.typeAhead.defaults.Ajax, {url: Ajax {{{{Ajax, $ .fn.typeAhead.defaults.ajax, ajax);} if (! this.ajax.url) {this.AJAX = null;}} this.listen ();} typeahead.prototype = {konstruktor: Typeahead, // ===================================================================== ======================================================================== // Utils //// ============================================================ =================================================================== ======================================/------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1.8 // eventsupported: function (eventName) {var issupported = (eventName di ini. $ Element); if (! Issupported) {this. $ Element.setAttribute (eventName, 'return;'); entsupported = typeof ini. $ Element [eventName] === Fungsi ';} return issupported;}, // ================================================================ ========================================================================= // Ajax //// ================================================================ =================================================================== ==========================/------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- itu;} // kueri berubahThat.query = kueri; // Batalkan timer terakhir jika setif (that.Ajax.timerId) {clearTimeOut (that.ajax.timerid); that.ajax.timerId = null;} if (! Query || query.length <that.ajax.triggerlength) {// Batalkan panggilan balik AJAX jika dalam kemajuan (that.ajax.xhr) {that.ajax.xhr.abort (); That.Ajax.XHR = null; that.AjaxtoggLeloadClass (false);} kembalikan itu. That.hide (): itu;} // kueri bagus untuk dikirim, atur a timerth.ajax.timerid = setTimeout (function () {$ .proxy (that.AjaxExecute (kueri), itu)}, that.Ajax.timeout); return that;},//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (query) {this.AjaxtoggleLoadClass (true); // Batalkan panggilan terakhir jika sudah ada di progresif (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 = null;}, // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- retreivalthis.ajax.data = data; item = this.grepper (this.ajax.data); if (! item ||! item.length) {return this.shown? this.hide (): this;} this.ajax.xhr = null; kembalikan this.render (items.slice (0, this.options.Items)). show ();}, // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (! this.ajax.loadingclass) return; this. $ element.toggleClass (this.ajax.loadingclass, aktifkan);}, // ============================================================================================================== =========================================================================================================================================== Data Manipulasi //// ==================================================== ==================================================================== ============================================KAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- itu. $ element.val (); if (! that.query) {return that.shown? itu.hide (): itu;} items = that.grepper (that.source); if (! item ||! items.length) {return that.shown? itu.hide (): itu;} return that.render (items.slice (0, that.options.items)).show();}},//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- itu = ini, item; if (data && data.length &&! data [0] .hasownProperty (that.options.display)) {return null;} item = $ .grep (data, fungsi (item) {return that.matcher (item [that.options.display], item);}); returner (item [that.options.display], item);}); return this.sorter (item);}, // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ~ item.TolowerCase (). IndexOf (this.query.tolowercase ());}, // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {beginswith.push (item);} else if (~ item [that.options.display] .indexof (this.query)) {caseSensitive.push (item);} else {caseinsensitive.push (item);}} return startswith.ccatcat (caseS sensitif, caseinsensitive);}, // ================================================================= ================================================================================= //// Dom Manipulasi //// ==================================================== ==================================================================== ==========================================================KAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ini. $ element [0] .OffsetHeight}); this. $ menu.css ({top: pos.top + pos.height, kiri: pos.left}); this. $ menu.show (); this.shown = true; return; this;},//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Highlights kecocokan di dalam hasil // highlighter: function (item) {var query = this.query.replace (/media/-/ media/ media {}()*+?.///^$ |#/s]/g, '// $ &'); return item.REPLACE (FUNGSI BARU ('(' (' + QUERY +'), FUNGSI ('( + + QUERY + {' + {'(' + {'( + + {' ( + + Query + '), {' ('( + + {' ('( + + Query + {' ('(' ( + query + ')) + match + '</strong>';});},//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Daftar // render: function (item) {var that = this; item = $ (item) .map (function (i, item) {i = $ (that.options.item) .attr ('value data', item [itu. i [0];}); items.first (). AddClass ('Active'); this. $ menu.html (item); return ini;},//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- this.hide ();}, // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Pilih hasil sebelumnya // 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');}, // ============================================================================================================= ==================================================================== ================================================================= /// Acara //// =========================================================== =================================================================== ====================================== // ------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ini)); if (this.eventsupported ('keyDown')) {this. $ element.on ('keydown', $ .proxy (this.keypress, this));} else {this. $ element.on ('keypress', $ .proxy (this.keypress, this));} ini. $ menu.on ('click', $. '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; case 27:/this.shown) {return;} this.select (); break; case 27:/this.shown) {return;} this.select (); break; case 27:/this.shown) {return; Escapethis.hide (); break; default: this.lookup ();}}, // ---------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- sedang ditekan // keypress: function (e) {e.stoppropagation (); if (! this.shown) {return;} switch (e.keycode) {case 9: // tabcase 13: // entercase 27: // Escapee.preventDefault (); break; case 38: // up dreventd develevault (); break; case 38: // up dreventd downprevent (); break; case 38://uprevent downpreventdefault (); break; case 38:/uprevent downpreventdefault (); break; case 38:/uprevent downprevent (); break; case 38:/up arrowe.preventDefault();this.next();break;}},//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Menangani Mengklik pada Daftar Hasil // Klik: Fungsi (e) {e.stoppropagation (); e.preventdefault (); this.select ();}, // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {this.$menu.find('.active').removeClass('active');$(e.currentTarget).addClass('active');}}//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {$ this.data ('TypeAhead', (data = typeahead baru (ini, opsi)));} if (typeOf option === 'string') {data [opsi] ();}});} // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- }, AJAX: {url: null, timeout: 300, Metode: 'pos', triggerLength: 3, LoadingClass: NULL, DisplayField: NULL, Predispatch: null, preprocess: null}} $. fn.typeAhead.constructor = Typeahead;//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- $ ('body'). off ('. Data-API') // Info lebih lanjut di sini: https://github.com/twitter/boottrap/tree/master/js//$(function () {$ ('body'). On ('focus.typeeahead.data-api', 'data-provide = "focum.typeeahead.data-pi', '[data-provovide =" ($ this.data ('TypeAhead')) {return;} e.preventDefault (); $ this.typeAhead ($ this.data ());})});} (window.jQuery);Di atas adalah kode contoh plug-in penyelesaian otomatis Bootstrap Automatic yang diperkenalkan kepada Anda oleh editor. Saya harap ini akan membantu Anda. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas Anda tepat waktu. Terima kasih banyak atas dukungan Anda ke situs web Wulin.com!