我在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肯定是加载的,我尝试过使用另一个变量$ - 任何想法还有什么可能是问题?
(编辑)自动完成的Drupal特定答案:
drupal_add_library('system', 'ui.autocomplete');
答案 0 :(得分:56)
<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>
答案 1 :(得分:3)
简单的解决方案: 在包含自动完整库时,序列非常重要:
<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>
答案 2 :(得分:2)
在我的经验中,我在我的文件中添加了两个Jquery库。版本是jquery 1.11.1和2.1.Suddenly我从我的代码中取出了2.1 Jquery。然后运行它,并为我工作。在尝试第一个答案后。请查看你上面说的文件。
答案 3 :(得分:0)
只需将这些添加到项目的库中即可
<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>
保存并重新加载。你很好走。
答案 4 :(得分:0)
尝试此代码,让$定义
(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);