Typeahead没有sugesset任何东西

时间:2013-06-06 09:44:53

标签: javascript html bootstrap-typeahead

我有一个HTML

<script type="text/javascript">
    var colors = ["red", "blue", "green", "yellow", "brown", "black"];
    $('#vahid').typeahead({source: colors});
</script>
<input type="text" id="vahid" data-provide='typeahead'>

但是typeahead没有任何建议。我的页面没有错误!

1 个答案:

答案 0 :(得分:1)

您在不存在的元素上执行typeahead尝试

<script type="text/javascript">
    $(document).ready(function() {
        var colors = ["red", "blue", "green", "yellow", "brown", "black"];
        $('#vahid').typeahead({source: colors});
    })
</script>
<input type="text" id="vahid" data-provide='typeahead'>

现在代码将在下载所有dom元素后执行