jQuery TypeError: $(...).autocomplete 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16300586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: $(...).autocomplete is not a function
提问by rix
I am getting the above error using the following code inside a Drupal module.
我在 Drupal 模块中使用以下代码收到上述错误。
jQuery(document).ready(function($) {
$("#search_text").autocomplete({
source:results,
minLength:2,
position: { offset:'-30 0' },
select: function(event, ui ) {
goTo(ui.item.value);
return false;
}
});
});
Jquery is definitely loaded, and I have tried using a different variable for $ - any ideas what else might be the problem?
Jquery 肯定已加载,我尝试为 $ 使用不同的变量 - 有什么想法可能还有什么问题吗?
(Edit) Drupal specific answer for autocomplete:
(编辑)Drupal 自动完成的特定答案:
drupal_add_library('system', 'ui.autocomplete');
回答by Ravi Gadag
you missed jquery ui library. Use CDN of Jquery UI or if you want it locally then download the file from Jquery Ui
你错过了 jquery ui 库。使用 Jquery UI 的 CDN 或者如果你想在本地使用它然后从Jquery Ui下载文件
<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet"></link>
<script src="YourJquery source path"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script>
回答by Mr world wide
Simple solution: The sequence is really matter while including the auto complete libraries:
简单的解决方案:在包含自动完成库时,顺序非常重要:
<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet"></link>
<script src='https://cdn.rawgit.com/pguso/jquery-plugin-circliful/master/js/jquery.circliful.min.js'></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script>
回答by Kumaresan Perumal
In my exprience I added two Jquery libraries in my file.The versions were jquery 1.11.1 and 2.1.Suddenly I took out 2.1 Jquery from my code. Then ran it and was working for me well. After trying out the first answer. please check out your file like I said above.
根据我的经验,我在我的文件中添加了两个 Jquery 库。版本是 jquery 1.11.1 和 2.1。突然我从我的代码中取出了 2.1 Jquery。然后运行它并且为我工作得很好。在尝试了第一个答案之后。请像我上面说的那样检查您的文件。
回答by OMi Shah
Just add these to libraries to your project:
只需将这些添加到您的项目的库中:
<link href="https://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet"></link>
<script src="https://code.jquery.com/ui/1.10.2/jquery-ui.min.js"></script>
Save and reload. You're good to go.
保存并重新加载。你很高兴去。
回答by joshua1234511
Try this code, Let $ be defined
试试这个代码,让 $ 被定义
(function ($, Drupal) {
'use strict';
Drupal.behaviors.module_name = {
attach: function (context, settings) {
jQuery(document).ready(function($) {
$("#search_text").autocomplete({
source:results,
minLength:2,
position: { offset:'-30 0' },
select: function(event, ui ) {
goTo(ui.item.value);
return false;
}
});
});
}
};
})(jQuery, Drupal);