TypeError:$(...).autocomplete不是一个函数

rix*_*rix 22 jquery

我在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;
            }        
    }); 
});
Run Code Online (Sandbox Code Playgroud)

Jquery肯定是加载的,我尝试使用另一个变量$ - 任何想法还有什么可能是问题?

(编辑)自动完成的Drupal特定答案:

drupal_add_library('system', 'ui.autocomplete');
Run Code Online (Sandbox Code Playgroud)

Rav*_*dag 61

你错过了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>
Run Code Online (Sandbox Code Playgroud)