我想设置自动完成字段。所以我写了
$(document).ready(function() {
$("#mytext").autocomplete({
source: function(request, response) {
$.getJSON("/ajax/autocomplete.php?term=" + $.trim(request.term), function(data) {
response($.map(data, function(item) {
return {label: highlightResult(item.label, $.trim(request.term))};
}));
});
},
minLength: 0
}).each(function() {
$(this).data("ui-autocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "</a>")
.appendTo(ul);
};
});
...
$("#mytext").focusin(function() {
$(this).autocomplete("search", $(this).val());
});
});
使用 HTML:
<div style="visibility: hidden;"/>
<input type="text" id="mytext" />
</div>
<button onclick="showDiv();">Click To Show</button>
此代码在 Google Chrome 上运行良好。但它在 IE 11 上运行很奇怪。
输入默认是隐藏的,但是当按钮被点击时它会出现。
奇怪的行为:
1) 刷新时,自动完成菜单出现在窗口(主体)的左上角。
2) 当文本框中有文本时,菜单不显示。我看到 data
参数有时(当有文本时)未定义 - 奇怪......
遇到这些问题我该怎么办?我没有找到任何有用的解决方案。
最佳答案
我也有同样的问题。页面刷新后显示一些自动完成功能。不知道为什么会发生这种情况,因为我在表单中有很多,而且只有很少的控件才会出现错误。
正如 Marc Thomann 所说的另一种修复方法 - 禁用自动完成和(我的技巧)添加
$(document).ready(function() {
...
/**** that is last line ***//
if (msieversion() === 11) {setTimeout(enable_autocomplete, 200);}
//函数 enable_autocomplete() 包含 $(".my_selector").autocomplete("option", "disabled", false); });
所以我的代码是:
var autocomplete_options = {/** your usual options **/};
if (msieversion() === 11) {
autocomplete_options.disabled = true;
};
$("#mytext").autocomplete(autocomplete_options);
关于javascript - 带有 IE 11 的 jQuery UI 自动完成 - 有线行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23118143/