Bootstrap-3-Typeahead在Chrome浏览器中不起作用

时间:2015-07-09 14:58:55

标签: jquery google-chrome twitter-bootstrap-3 bootstrap-typeahead

我正在使用bootstrap version3.3.5和bootstrap-3-typeahead。 Typeahead在firefox中工作正常,但在chrome中不起作用。我得到了Uncaught typeerror:“TypeError:$(...)typeahead不是函数”。我正在使用django框架。使用grunt将typeahead.js包含在bootstrap.js文件中。

我在浏览时发现它可能因以下原因而发生: -

  1. jQuery在bootstrap.js。
  2. 之后加载
  3. jQuery不止一次加载。
  4. 但这两个似乎都不适合我的代码.Code如下: -

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        {% load staticfiles %}
        <!-- Bootstrap -->
        <link rel="stylesheet" href="{% static "bootstrap/css/bootstrap.min.css" %}">
        <link rel="stylesheet" href="{% static "bootstrap/css/bootstrap-theme.min.css" %}">
    
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    

    / * 其余的html ..没有JS或Jquery之间加载。 * /

        <script src="{% static "jquery/jquery.min.js" %}"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="{% static "bootstrap/js/bootstrap.min.js" %}"></script>
        <script type="text/javascript">
            $(document).ready(function() {
    
                $('#id_area').typeahead({
                    source: function (query, process) {
                        return $.get('/user/match/area/?q=' + query, function (data) {
                            return process(data.search_results);
                        });
                    }
                });
                function customwidth()
                {
                    var formwidth = $('#adv-search').width();       
                    $('.dropdown-menu').width(formwidth- 40);   
                };
    
                customwidth();
                $(window).resize(function(e) {
                    customwidth();
                });
            });
        </script>
    

    我上线的错误 - $('#id_area')。typeahead({。我无法弄清问题是什么。请帮忙。

1 个答案:

答案 0 :(得分:1)

我不确定出了什么问题。但在清除浏览器缓存(ctrl + F5)后,它开始工作正常。

如果有人知道可能出了什么问题,请告诉我。这可能在将来帮助我。