رمز المفتاح كما يلي:
$ ('#sale'). typeAhead ({ajax: {url: '@url.action ("../ unget/getsale")' ، {$ ("#salesid"). val (val) ؛}}) ؛هذا الإكمال التلقائي TypeAhead ليس typeahead.js شائع الاستخدام في bootstrap. فيما يلي رمز typeahead.js (من الأفضل أن يكون هناك bootstrap3-typeahead.js)
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bootstrap typeahead plugin // 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 ، reports) ؛ this. $ menu = $ (this.options.menu) .appendto ('body') ؛ this.shown ؛ 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 || هذا. هذا. $ .fn.typeahead.defaults.ajax ، ajax) ؛} if (! this.ajax.url) {this.ajax = null ؛}} this.listen () ؛} typeahead.prototype = {constructor: TypeAhead ، // ============================================================= ======================================================================== ^ utils //// ======================================================= =============================================================== ======================================/------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1.8 // eventupported: function (eventName) {var issupported = (eventName in this. $ element) ؛ if (! issupported) {this. $ element.setattribute (eventName ، 'return ؛') issupported ؛} ، // =========================================================== ========================================================================= ^ ajax /////======================================================== =============================================================== ============================/-------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- that ؛} // query change that.query = query ؛ // cancel timer last if 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 ؛} // الاستعلام أمر جيد لإرساله ، تعيين توقيت. That ؛} ، // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {this.ajaxtoggloadClass (true) ؛ // إلغاء المكالمة الأخيرة إذا بالفعل في Progressif (this.ajax.xhr) this.ajax.xhr.abort () ؛ var params = this.ajax.predispatch؟ this.ajax.predispatch (استعلام): {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 ؛ العناصر = this.grepper (this.ajax.data) ؛ if (! items ||! items.length) {return this.shown؟ this.hide (): this ؛} this.ajax.xhr = null ؛ return this.render (items.slice (0 ، this.options.items) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (! this.ajax.loadingClass) إرجاع ؛ هذا. $ element.toggleclass تمكين) ؛} ، // ========================================================================================================================= ===========================================================================================سف بيانات التلاعب /////=================================================== ================================================================ ========================================================! ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- هذا. $ element.val () ؛ if (! that.query) {return that.shown؟ that.hide (): that ؛} العناصر = that.grepper (that.Source) ؛ if (! items ||! items.length) {return that.shown؟ that.hide (): that ؛} إرجاع ذلك. render (items.slice (0 ، that.options.items) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- هذا = هذا ، العناصر ؛ if (data && data.length &&! data [0] .hasOwnProperty (that.options.display)) {return null ؛} عناصر = $ .grep (data ، function (item) {return that.matcher (item [that.options.display] ، item) ؛}) ؛ هذا. ~ item.tolowercase (). indexof (this.query.tolowercase ()) ؛} ، // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {phinswith.push (item) ؛} if (~ item [that.options.display] .indexof (this.query)) {caseencist.push (item) ؛} else {caseInsevitive.push (item) ؛}} return with. CaseinsEvitive) ؛} ، // ============================================================ ============================================================================= ^ دوم التلاعب /////=================================================== ================================================================ ============================================================= // --------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- هذا. $ element [0] .offSetheight}) ؛ هذا. $ menu.css ({top: pos.top + pos.height ، اليسار: pos.left}) ؛ هذا. $ menu.show () ؛ this.shown = true ؛ this;},//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Highlights The Match (es) داخل النتائج // Highlighter: function (item) {var query = this.query.replace (/budap/-/ budud//2010er + match + '</strong>';});},//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- list // render: function (عناصر) {var that = this ؛ items = $ (items) .map (function (i ، item) {i = $ (that.options.item) .Attr ('data-value' ، item [that.options.val]) ؛ i.find ('a'). i [0] ؛}) ؛ items.first (). addClass ('نشط') ؛ هذا. $ menu.html (العناصر) ؛ العودة هذا؛}،//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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 ، this)) ؛ هذا)). this));},//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- being raised up//keyup: function (e) {E.StopPropagation () ؛ Escapethis.hide () ؛ Break ؛ افتراضي: this.lookup () ؛ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- يجري الضغط عليه // Keypress: function (e) { Arrowe.PreventDefault () ؛ this.next () ؛ break ؛}} ، // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- المقابض النقر فوق قائمة النتائج // انقر فوق: الدالة (هـ) {E.StopPropagation () ؛ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {this. $ menu.find ('. active'). removeclass ('active') ؛ $ ( ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ {$ this.data ('typeahead' ، (data = new typeahead (هذا ، خيارات))) ؛} if (typeof Option === 'string') {Data [Option] () ؛}}) ؛} // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ } ، ajax: {url: null ، timeout: 300 ، method: 'post' ، triggerlength: 3 ، loadingclass: null ، displayfield: null ، frispatch: null ، preprocess: null}} $. fn.typeahead.constructor = Typeahead;//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- $ ('body'). OFF ('. data-api') // مزيد من المعلومات هنا: https://github.com/twitter/bootstrap/tree/js/js//$(function () {$ ('body'). on ('focus.typead.data-api' ، ' $ (this) ؛ if ($ this.data ('typeahead')) {return ؛}ما ورد أعلاه هو رمز الإكمال التلقائي tytstrap typeahead مثال على ما قدمه لك المحرر. آمل أن يكون ذلك مفيدًا لك. إذا كان لديك أي أسئلة ، فيرجى ترك رسالة لي وسوف يرد المحرر إليك في الوقت المناسب. شكرا جزيلا لدعمكم لموقع wulin.com!