我花了很多时间试图找出是什么阻止了 jQuery 自动完成功能的工作,所以非常感谢任何帮助。我在 IE 中收到以下错误,在 Chrome 和 Firefox 中收到类似错误:
JavaScript 运行时错误:对象不支持属性或方法“自动完成”
根据我的研究,我了解到这是由于 js 引用文件造成的,但我见过的解决方案都不起作用。以下是 js-ui 和通用 js 文件的引用:
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Custom data and display</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.js"></script>
</head>
这是我实现它的地方:
<script type="text/javascript">
$(document).ready(function () {
$("#school").autocomplete ({
minLength: 2,
source: schools,
select: function (e, ui) {
e.target.value = ui.item.label;
$("#schoolValue").val(ui.item.value);
e.preventDefault();
}
});
</script>
<input id="school" class="register-field" placeholder="School" type="text" />
这让我非常疯狂,所以我再次感谢您的帮助!
最佳答案
试试这个:
<script type="text/javascript">
$(function () {
$("#school").autocomplete ({
minLength: 2,
source: schools,
select: function (e, ui) {
e.target.value = ui.item.label;
$("#schoolValue").val(ui.item.value);
e.preventDefault();
}
});
});
</script>
<input id="school" class="register-field" placeholder="School" type="text" />
关于javascript - jQuery 自动完成功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33088450/