我有一个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'>


但预先输入并不能表示任何建议。我的页面没有错误!

最佳答案

您在不存在的元素上尝试提前输入

<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元素下载后执行

关于javascript - 提前输入不提示任何内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16958825/

10-09 19:37