【问题标题】:jquery cookie doesn't work on localhost even in firefox即使在 Firefox 中,jquery cookie 在 localhost 上也不起作用
【发布时间】:2015-12-12 15:43:25
【问题描述】:

实际上问题已经在标题中描述)几个时刻:

    <script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" scr="{% static "jquery.cookie.js" %}">
    </script>    

但是在 Chrome/Firefox 的控制台中 - $.cookie 没有定义

    $.cookie
    undefined

感谢回答

【问题讨论】:

    标签: html django firefox cookies localhost


    【解决方案1】:

    jquery.cookie.js 文件的代码中有拼写错误,您拼写为 scr 而不是 src。正确的行是:

    <script type="text/javascript" src="{% static "jquery.cookie.js" %}">
    </script>    
    

    如果这不起作用,请检查{% static %} 标记是否确实输出了有效的 URL(只需从那里复制 URL 并在浏览器中尝试)。

    【讨论】:

    • 还要确保您没有在jquery.cookie.js 行下方的某个位置再次导入jquery。这种情况经常发生...有另一个jquery 导入将覆盖原始jquery 的引用,jquery.cookie 注册到的引用
    • 我在模板末尾导入了 jquery 用于引导程序。现在我删除它。但是……还是不行。我在 Watch 中添加了屏幕截图 prntscr.com/9dia9k。我认为 $ 和 jQuery active = 0 不好。我希望我能修复它。但我是 JS 的新手
    • @nurekil scr 错字仍然存在。能否请您发布plunker 或其他内容,以便我可以看到整个生成的 HTML?
    • 你是对的 - 我“拼写为 scr 而不是 src”。我以为如果我写错了调试器会说出来。感谢您的帮助
    【解决方案2】:

    你可以用这个

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

    【讨论】:

      猜你喜欢
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多