我使用的是Materialize CSS库,其中有一个创建autocomplete dropdown的选项(您可以在页面末尾找到它)
如果我尝试使用它,当我键入某些内容时,它会显示以下错误
未捕获TypeError: this.source不是函数
at t.(匿名函数).(匿名函数)._search (http://localhost/imgup/js/jquery-ui.min.js:2345:101)
at t.(匿名函数).(匿名函数)._search (http://localhost/imgup/js/jquery-ui.min.js:139:77)
at t.(匿名函数).(匿名函数).search (http://localhost/imgup/js/jquery-ui.min.js:2341:175)
at t.(匿名函数).(匿名函数).search (http://localhost/imgup/js/jquery-ui.min.js:139:77)
at t.(匿名函数)。(匿名函数)。(http://localhost/imgup/js/jquery-ui.min.js:2337:74)
在I (http://localhost/imgup/js/jquery-ui.min.js:302:62)
我搜索了这个问题,但没有找到任何有用的答案
这是我的Materialize CSS - HTML代码
<input type="text" id="autocomplete-input" class="autocomplete">
这是用于自动补全的javascript
$('input.autocomplete').autocomplete({
data: {
"Apple": null,
"Microsoft": null,
"Google": 'http://placehold.it/250x250'
},
limit: 20, // The max amount of results that can be shown at once. Default: Infinity.
onAutocomplete: function(val) {
// Callback function when value is autcompleted.
},
minLength: 1, // The minimum length of the input for the autocomplete to start. Default: 1.
});
还有一些屏幕截图,我在下面的错误日志中看到错误
控制台出错:
文件中出现错误- 1:
文件中出现错误- 2:
文件中出现错误- 3:
文件中出现错误- 4:
文件中出现错误- 5:
我该如何解决这个问题呢?请帮帮我
发布于 2017-03-25 23:17:27
您使用的是哪个版本的jQuery/Materialize?看看这支笔,它在哪里工作:
http://codepen.io/anon/pen/RpBRjJ
您是否将jQuery代码包装在类似于$(document).ready()
的代码中
发布于 2018-08-19 22:37:15
如果您正在加载jquery-ui
,则错误
this.source不是一个函数“
也会发生。
在这种情况下,您不能使用jquery $('input.autocomplete').autocomplete()
,但需要使用M.Autocomplete
替代调用。
https://stackoverflow.com/questions/43018022
复制相似问题