所以,我在我的一个领域中使用了 Materialize CSS 自动完成功能,但我想知道为什么会出现此错误?
Uncaught TypeError: $(...).autocomplete is not a function
at HTMLDocument.<anonymous> (edit_view.php?id=48:568)
at j (jquery-2.1.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-2.1.1.min.js:2)
at Function.ready (jquery-2.1.1.min.js:2)
at HTMLDocument.I (jquery-2.1.1.min.js:2)
这是我的功能:
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$.ajax({
type: 'GET',
url: 'http://127.0.0.1/EnrollmentSystem/views/employee/departments.php',
success: function(response) {
var departmentArray = response;
var dataDepartment = {};
for (var i = 0; i < departmentArray.length; i++) {
console.log(departmentArray[i].name);
dataDepartment[departmentArray[i].name] = departmentArray[i].flag;
}
$('input.autocomplete').autocomplete({
data: dataDepartment,
});
}
});
});
});
</script>
并在这里调用它:
<div class="col s12 m8 l8">
<input type="text" id="department" name="department_id" value="<?php echo $department['name'] ;?>" class="autocomplete">
</div>
我尝试了不同版本的JQuery,但我没有运气。这些是我获取 Javascript 的声明:
<script type = "text/javascript"
src = "https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
我在 stackoverflow 中尝试了不同的建议,但对我的情况没有任何作用。 希望有人能指出我该如何解决这个错误
最佳答案
自动完成
在0.97.3中不可用,它是在1.0.0中添加的(以及其他与表单相关的功能)。此外,1.0.0 不依赖于 jQuery,因此语义不同。 1.0.0 中的自动完成
文档为 over here .
关于javascript - 如何解决AutoComplete不是materializecss的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56822497/