Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 下拉菜单不工作_Html_Ruby On Rails_Twitter Bootstrap - Fatal编程技术网

Html 下拉菜单不工作

Html 下拉菜单不工作,html,ruby-on-rails,twitter-bootstrap,Html,Ruby On Rails,Twitter Bootstrap,我正在做一个项目。我在顶部有一个导航栏,在导航栏中有一个不起作用的下拉菜单。我已经忽略这个问题有一段时间了,但是现在我需要下拉菜单中的东西。我一直在慢慢地从我的项目中找出原因。现在,我已经将导航栏(位于头文件中)替换为 这是my_header.html.erb(除了head标记外,与引导程序几乎相同) $('.dropdown toggle').dropdown() 切换导航 提交 这是我的application.html.erb <

我正在做一个项目。我在顶部有一个导航栏,在导航栏中有一个不起作用的下拉菜单。我已经忽略这个问题有一段时间了,但是现在我需要下拉菜单中的东西。我一直在慢慢地从我的项目中找出原因。现在,我已经将导航栏(位于头文件中)替换为

这是my_header.html.erb(除了head标记外,与引导程序几乎相同)


$('.dropdown toggle').dropdown()
切换导航
提交
这是我的application.html.erb

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag "application", media: "all","data-turbolinks-track" => true %>

    <%= javascript_include_tag "application", "data-turbolinks-track" => true%> 
    <%= javascript_include_tag "http://localhost:9292/faye.js"%> 
    <%= javascript_include_tag "autocomplete-rails.js" %>    
    <%= include_gon %>

    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>
  </head>
  <body>
    <div class="container" style = "width: 100%; padding: 0px">
      <%= render 'layouts/header' %>
    </div>
  </body>
</html>

正确%>
正确%>

页面加载,但当我点击“下拉”时,什么都没有发生。我被难住了,有人有什么想法吗??我也一直在检查我的代码,寻找语法错误,但没有发现任何错误。由于我仍然在引导代码中遇到相同的错误,因此语法错误似乎不太可能是原因。

刚刚查看了部分
\u header.hml.erb
,注意到其中有一个
头标记。你应该移除它

如果您查看
application.html.erb
布局,您已经有了一个head标签,并且您正在将_header.html.erb部分呈现在您的body标签中

你有

<%= javascript_include_tag "application", "data-turbolinks-track" => true%>

我使用了用于合并turbolinks的函数

您能给我们显示CSS部分还是在FIDLE中复制这个部分?引导程序.js..在app>assets>javascript中,至于CSS。css是自举的。大约4000行。我只是在fiddle中尝试了一下,结果不是那么好,greatI添加了true%>现在下拉列表显示了。谢谢所以我必须为我所有的javascript文件写一行这样的代码吗?是的,你应该在assets/javascript文件夹中编写所有的js。为重要的js函数创建单独的文件,如果项目中没有足够的js,则只创建一个文件,然后在application.js文件中需要该文件。欲了解更多信息,请阅读
<%= javascript_include_tag "application", "data-turbolinks-track" => true%>
<head>
  <script type="text/javascript">
    $('.dropdown-toggle').dropdown()
  </script>
</head>
$(document).on("click",".dropdown-toggle",function(){
  $(this).dropdown();
});