简体   繁体   English

jQuery UI自动完成功能停止工作

[英]jQuery UI Autocomplete stopped working

For some reason jQuery UI's autocomplete has stopped working for me. 由于某种原因,jQuery UI的自动完成功能已停止为我工作。 I get the same error as is described on this webpage . 我收到与此网页中所述相同的错误。

I've copied the content of the query from that webpage below, hoping that somebody here will be able to answer it. 我已经从下面的网页复制了查询的内容,希望这里的人能够回答。

Thanks! 谢谢!

I am using Jquery UI Autocomplete to get a list of names. 我正在使用Jquery UI Autocomplete来获取名称列表。 But for some reason I am getting an error: 但是由于某种原因,我遇到了一个错误:

替代文字

 $('#repName').removeAttr('readonly').focus(function () { $(this).val(''); }).autocomplete({ source: function (request, response) { tagId = $('#TagId').val(); $.ajax({ url: '/Developement/GetRepName', type: 'POST', dataType: 'json', data: { searchText: request.term, maxResults: 10, tagId: tagId }, success: function (data) { response($.map(data, function (item) { return { label: item.Name, value: item.RepId, id: item.RepId } })) } }) }, select: function (event, ui) { commissionAllicationModifications(ui.item.id, 0, 'A'); } }); 

I have no clue why this is happening. 我不知道为什么会这样。 I am using Jquery UI 1.8.1. 我正在使用Jquery UI 1.8.1。

I would appreciate any kind of help on this. 我将不胜感激。

It is coming from the jQuery UI 1.8.1 file, specifically jQuery UI Autocomplete 1.8.1. 它来自jQuery UI 1.8.1文件,特别是jQuery UI Autocomplete 1.8.1。

  .menu({ focus: function (event, ui) { var item = ui.item.data("item.autocomplete"); if (false !== self._trigger("focus", null, { item: item })) { // use value to match what will end up in the input, if it was a key event if (/^key/.test(event.originalEvent.type)) { self.element.val(item.value); } } }, selected: function (event, ui) { var item = ui.item.data("item.autocomplete"); if (false !== self._trigger("select", event, { item: item })) { self.element.val(item.value); } self.close(event); // only trigger when focus was lost (click on menu) var previous = self.previous; if (self.element[0] !== doc.activeElement) { self.element.focus(); self.previous = previous; } self.selectedItem = item; }, * blur: function (event, ui) { * if (self.menu.element.is(":visible")) { * self.element.val(self.term); * } * } }) .zIndex(this.element.zIndex() + 1) // workaround for jQuery bug #5781 http://dev.jquery.com/ticket/5781 .css({ top: 0, left: 0 }) .hide() .data("menu"); 

It is weird though because this works flawlessly in another project. 但这很奇怪,因为这在另一个项目中可以完美地工作。 What I noticed is when the code hits the [starred] section the self.menu section is undefined. 我注意到的是,当代码到达[starred]部分时,self.menu部分未定义。 Another thing of note was that it doesn't even send the request. 值得注意的另一件事是它甚至不发送请求。 I was thinking that it might be my focus function. 我当时以为这可能是我的重点职能。

 .focus(function () { $(this).val(''); 

But it is not. 但事实并非如此。 Thank you for you help. 谢谢你的帮助。

It turns out that I included a plugin that defined $.fn.menu and this wrought havoc. 事实证明,我包括一个定义$.fn.menu的插件,并且造成了严重破坏。 I changed it to $.fn.fg_menu and the problem was resolved. 我将其更改为$.fn.fg_menu ,问题已解决。

What version of jQuery core are you using? 您正在使用哪个版本的jQuery core?

I know of a bug related to visible detection and related to IE8 . 我知道与可见检测IE8有关的错误。 If possible, can you upgrade to the most recent jQuery on a test machine and see if that solves your problem? 如果可能,您可以在测试机上升级到最新的jQuery,看看是否可以解决您的问题?

If you don't feel like upgrading, you could also try hacking jQuery (UGLY!) - with this : 如果你不喜欢升级,你也可以尝试黑客的jQuery(太丑了!) - 与此

if (self.menu.element.is(":visible"))

becomes

if (!(self.menu.element.css('display') == 'none'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM