jQuery(...)。autoComplete不是一个函数

时间:2016-08-22 19:10:38

标签: jquery jquery-ui autocomplete

我正在尝试使用jQuery-ui来运行autoComplete()。我创建了一个小提示来显示我的代码:

https://jsfiddle.net/4s4dzwn1/

我的JS:

jQuery(function(){

    jQuery('#autocomplete').autoComplete({
        source: ["ActionScript",
            "Bootstrap",
            "C",
            "C++",
            "Ecommerce",
            "Jquery",
            "Groovy",
            "Java",
            "JavaScript",
            "Lua",
            "Perl",
            "Ruby",
            "Scala",
            "Swing",
            "XHTML"]
    });

});

我的HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<form>
    <input id="autocomplete">
</form>

它抛出一个错误,说autoComplete不是一个函数。我的理解是autoComplete是jQuery-ui(包括在内)的一部分,jQuery-ui应该包含在之后 jquery。请纠正我错在哪里。

1 个答案:

答案 0 :(得分:2)

尝试此代码

&#13;
&#13;
jQuery(function(){

    jQuery('#autocomplete').autocomplete({
        source: ["ActionScript",
            "Bootstrap",
            "C",
            "C++",
            "Ecommerce",
            "Jquery",
            "Groovy",
            "Java",
            "JavaScript",
            "Lua",
            "Perl",
            "Ruby",
            "Scala",
            "Swing",
            "XHTML"]
    });

});
&#13;
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

    <form>
        <input id="autocomplete">
    </form>
&#13;
&#13;
&#13;