jquery 自动完成:this.menu 未定义
我正在使用 jQuery UI 自动完成功能来获取一些数据。现在我有 3 个自动完成元素,其中 2 个可以正常工作,一个则不能。在页面开头,他给了我错误 elem.ownerDocument is null
。当我将文本放入 input
字段时,他找到结果,但收到错误 this.menu is undefined (jquery.js line 6012)
,它引用了 ul列出应显示结果的位置。
这里有一些代码:
$("#iName").autocomplete({
source: widget.festivals_list,
autofocus: true,
focus: function (e, ui) {
return false;
},
search: function (event, ui){
ownFest = true;
$("#iDate").removeAttr("disabled");
$("#iTime").removeAttr("disabled");
},
select: function (event, ui) {
ownFest = false;
$(event.target).val(ui.item.label);
selectedN = ui.item.value;
$(widget.festivals).each(function fn(){
if(this.id == ui.item.value){
$("#iDate").val(this.date).attr("disabled", "disabled");
$("#iTime").val(this.time).attr("disabled", "disabled");
}
});
return false;
}
});
HTML 代码:
<table>
<tr>
<td>Type the name</td>
</tr>
<tr>
<td><input type="text" id="iFest"/></td>
</tr>
</table>
这会在我的 input
标记上创建典型数量的属性,并创建 ul
列表。
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem"></ul>
<input id="iFest" class="ui-autocomplete-input" type="text" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
有人也遇到过这些问题吗? 谢谢
(使用 jQuery 1.5.2 和 jQuery UI 1.8.11)
谢谢
I'm using the jQuery UI Autocomplete for some data. Now I have 3 autocomplete elements and 2 of these work fine, one doesn't. At the start of the page he gives me the error elem.ownerDocument is null
. When I put text into the input
field he find result but I get the error this.menu is undefined (jquery.js line 6012)
which refers to the ul list
where the result should be shown.
Here some code:
$("#iName").autocomplete({
source: widget.festivals_list,
autofocus: true,
focus: function (e, ui) {
return false;
},
search: function (event, ui){
ownFest = true;
$("#iDate").removeAttr("disabled");
$("#iTime").removeAttr("disabled");
},
select: function (event, ui) {
ownFest = false;
$(event.target).val(ui.item.label);
selectedN = ui.item.value;
$(widget.festivals).each(function fn(){
if(this.id == ui.item.value){
$("#iDate").val(this.date).attr("disabled", "disabled");
$("#iTime").val(this.time).attr("disabled", "disabled");
}
});
return false;
}
});
HTML CODE:
<table>
<tr>
<td>Type the name</td>
</tr>
<tr>
<td><input type="text" id="iFest"/></td>
</tr>
</table>
This creates the typical number of attributes on my input
tag and creates the ul
list.
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem"></ul>
<input id="iFest" class="ui-autocomplete-input" type="text" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
Someone who also had these problems?
Thanks
(Using jQuery 1.5.2 and jQuery UI 1.8.11)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信这是因为你的“这个”超出了范围。
在函数内部,“this”并不总是您想象的那样。
通常的解决方案是引用全局“this”
或
当您在函数中时引用元素而不是“this”。
你也可以发布你的 HTML 吗?或者指出哪一行有错误?从你的片段中我似乎看不到它。
I believe its because your 'this' is out of scope.
Inside a function, 'this' isn't always what you think it is.
usual solution is to make a reference to your global 'this'
or
And refer to element instead of 'this' when you're in a function.
Can you post your HTML too ? or indicate which line has the error ? I can't seem to see it from your snippet.
您缺少自动完成引用的库。
所以,包括这一点:
祝你好运!
You are missing a library referenced by autocomplete.
So, include this:
Good luck!