我正在使用jQuery UI Autocomplete来处理一些数据。现在我有3个自动完成元素,其中2个工作正常,但没有。在页面开头,他给了我错误elem.ownerDocument is null
。当我将文字放入input
字段时,他会找到结果,但我收到的错误this.menu is undefined (jquery.js line 6012)
引用了应显示结果的ul list
。
这里有一些代码:
$("#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>
这会在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)
由于
答案 0 :(得分:0)
我相信它是因为你的'这个'超出了范围。
在一个函数中,'this'并不总是你想象的那样。
通常的解决方案是引用您的全球'this'
var element = $(this);
或
var me = this;
当你在一个函数中时,引用元素而不是'this'。
你也可以发布你的HTML吗?或指出哪一行有错误?我似乎无法从你的片段中看到它。
答案 1 :(得分:0)
您缺少自动填充引用的库。
所以,包括这个:
<script type="text/javascript" src="js/ui/jquery.ui.menu.js"></script>
祝你好运!