简体   繁体   English

引导程序下拉按钮

[英]Bootstrap Dropdown Button

I am currently using Bootstrap 3, with Ruby on Rails and I'm having some issues with a dropdown button. 我目前正在将Bootstrap 3与Ruby on Rails一起使用,并且下拉按钮存在一些问题。 The button does drop down and shows the list items, but upon clicking on one I'm taken to the top of the page and no list item was selected. 该按钮确实会下拉并显示列表项,但是单击某个按钮后,我被带到页面顶部,并且未选择任何列表项。

Here's the code for the dropdown button - html.erb file 这是下拉按钮的代码-html.erb文件

   <div class="col-md-5 col-md-offset-2 col-xs-12"> 
          <div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
    How many?

  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
    <li><a href="#">1</a></li>
    <li><a href="#">2-9</a></li>
    <li><a href="#">10+</a></li>
  </ul>
</div>
</div>
        </div>

My knowledge of JS is non-existent so I've been looking at other people's questions but I'm still unable to work it out. 我不了解JS,因此我一直在研究其他人的问题,但仍然无法解决。

The script also in the html.erb file 该脚本也位于html.erb文件中

<script type="text/javascript" src="js/bootstrap/bootstrap.js"></script>
<script>
     $(document).ready(function(){
        $('.dropdown-toggle').dropdown()
    });
</script>

When running the app the Javascript console throws up a 404 not found for bootstrap.js. 运行该应用程序时,Javascript控制台会抛出bootstrap.js找不到的404。 I currently have the bootstrap under Vendor/assets/javascripts/bootstrap.js 我目前在Vendor / assets / javascripts / bootstrap.js下有引导程序

Should the bootstrap JS files be under app/assets/javascripts? 引导JS文件是否应位于app / assets / javascripts下?

Hopefully someone is able to shed some light on what I'm doing wrong. 希望有人能够阐明我做错了什么。

It seems to a href attribute problem in the "a" element. 似乎是“ a”元素中的href属性问题。 Remove a literal "#" and try again. 删除文字“#”,然后重试。

And all of loaded file path whatever you want to load from your local storage should be path for based on your local storage too. 无论您要从本地存储中加载什么,所有已加载的文件路径也都应基于本地存储。 that is, apps/asset/javascript path is correct. 也就是说,apps / asset / javascript路径正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM