【问题标题】:bootstrap/javascript dropdown menu not working on herokubootstrap/javascript 下拉菜单在 heroku 上不起作用
【发布时间】:2016-08-05 05:14:32
【问题描述】:

我的应用程序在我的本地计算机上运行良好,但是,当我将其部署到 heroku 时,导航栏上的下拉菜单无法正常工作...这是下拉菜单的代码

 <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown"> Learning Wellness <span class="caret"></span> </a>
        <ul class="dropdown-menu">
          <li><% yield (:exercise)%><%= link_to "Exercise", exercise_path%></li>
          <li><% yield (:eating_healthy)%><%= link_to "Eating Healthy", eating_healthy_path%></li>
          <li><% yield (:safety)%><%= link_to "Safety", safety_path%></li>
          <li><% yield (:health_awareness)%><%= link_to "Health & Awareness", health_awareness_path%></li>
        </ul>
      </li>

      <script type="text/javascript">
        $('.dropdown-toggle').dropdown()
      </script>

我已经将所有资产设置为预编译,并且我尝试过手动进行。不知道为什么它不起作用

编辑:

应用程序.js

//= require turbolinks
//= require_tree .
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require bootstrap
//= require jquery.slick
//= require initialize

【问题讨论】:

    标签: javascript jquery ruby-on-rails twitter-bootstrap heroku


    【解决方案1】:

    你需要添加document.ready函数:

    $( document ).ready(function() {
        $('.dropdown-toggle').dropdown();
    });
    

    而不是

    $('.dropdown-toggle').dropdown();
    

    问候!

    【讨论】:

    • 添加代码,推送到 Heroku,仍然没有雪茄:/
    • 我想你已经包含了 jquery 和 bootstrap js 库。
    • 是的,我在原始帖子中添加了一张图片
    猜你喜欢
    • 2018-05-12
    • 1970-01-01
    • 2013-01-21
    • 2012-03-20
    • 2021-12-19
    • 2020-07-13
    • 2018-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多