Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.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
Javascript Rails和JQuery下拉列表_Javascript_Jquery_Html_Css_Ruby On Rails - Fatal编程技术网

Javascript Rails和JQuery下拉列表

Javascript Rails和JQuery下拉列表,javascript,jquery,html,css,ruby-on-rails,Javascript,Jquery,Html,Css,Ruby On Rails,我试图在ruby on rails站点中使用JQuery创建一个菜单栏/下拉列表,我在application.js文件中包含了JQuery代码,因为我希望它应用于我网站中的每个文件,菜单在application.html.erb文件中,以便稍微干燥一下视图 jquery代码在第一次运行时工作得很好,例如,我可以导航到一个页面并使用导航栏返回主页,但是一旦返回主页,除非我手动刷新页面,否则下拉列表不起作用,就好像jquery根本没有加载一样,这可能是rails缓存文件而不是重新加载文件弄乱了我的文

我试图在ruby on rails站点中使用JQuery创建一个菜单栏/下拉列表,我在application.js文件中包含了JQuery代码,因为我希望它应用于我网站中的每个文件,菜单在application.html.erb文件中,以便稍微干燥一下视图

jquery代码在第一次运行时工作得很好,例如,我可以导航到一个页面并使用导航栏返回主页,但是一旦返回主页,除非我手动刷新页面,否则下拉列表不起作用,就好像jquery根本没有加载一样,这可能是rails缓存文件而不是重新加载文件弄乱了我的文档的结果吗

任何帮助,将不胜感激,我如何才能使这一功能继续

(application.js)Jquery:


这是Rails TurboLink的一个问题。应改为使用:

$(document).on('ready page:load', function() {
  // Your implementation here ...
});
查看
<div id='cssmenu'>
    <ul>
      <li class='has-sub'><a href='/'><span>Account Actions</span></a>
        <ul>
          <% if user_signed_in? %>
              <li><a href= <%= edit_user_registration_path %> ><span> <%=  t('editprofileuser') %></span></a></li>
              <li class='last'><a class="navbar-link" rel="nofollow" data-method="delete" href= <%= destroy_user_session_path %>><span><%=  t('logoutuser') %></span></a></li>
          <% elsif company_signed_in? %>
          <li><a href= <%= edit_company_registration_path %> ><span> <%=  t('editprofilecompany') %></span></a></li>
          <li class='last'><a class="navbar-link" rel="nofollow" data-method="delete" href= <%= destroy_company_session_path %>><span><%=  t('logoutcompany') %></span></a></li>
          <% else %>
              <li><a href= <%= new_user_registration_path %> ><span> <%=  t('signupuser') %></span></a></li>
              <li><a href= <%= new_user_session_path %> ><span> <%=  t('loginuser') %></span></a></li>
              <li><a href= <%= new_company_registration_path %> ><span> <%=  t('signupcompany') %></span></a></li>
              <li class='last'><a href= <%= new_company_session_path %> ><span><%=  t('logincompany') %></span></a></li>
          <% end %>
        </ul>
      </li>
      <li class='has-sub'><a><span>Navigation</span></a>
        <ul>
          <li class='last'><a href= '/'><span>Homepage</span></a></li>
          <li class='last'><a href= 'audits' ><span>View My Audits</span></a></li>
        </ul>
      </li>
      <li><a href= <%= root_path %> ></a>root</li>
      <% if user_signed_in? %>
          <li class='has-sub'><a href='#'><span><%= t('loggedinas') %> <%= current_user.email %></span></a>
      <% elsif company_signed_in? %>
          <li class='has-sub'><a href='#'><span><%= t('loggedinas') %> <%= current_company.email %></span></a>
      <% end %>
    </ul>
  </div>
   @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,600,300);
    @charset "UTF-8";
/* Base Styles */
#cssmenu,
#cssmenu ul,
#cssmenu li,
#cssmenu a {
    margin: 0;
    padding: 0;
    border: 0;
    list-style: none;
    font-weight: normal;
    text-decoration: none;
    line-height: 1;
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    position: relative;
    }
#cssmenu a {
    line-height: 1.5;
    }
#cssmenu {
    width: 100%;
    background: #fff;
    }
#cssmenu > ul {
    border: 1px solid #000000;
    -moz-box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.2);
    -webkit-box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.2);
    box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.2);
    background: #565656;
    background: -moz-linear-gradient(#565656 0%, #323232 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #565656), color-stop(100%, #323232));
    background: -webkit-linear-gradient(#565656 0%, #323232 100%);
    background: linear-gradient(#565656 0%, #323232 100%);
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    }
#cssmenu > ul:after {
    clear: both;
    content: '';
    display: table;
    }
@media all and (max-width: 480px) {
    #cssmenu > ul {
        max-height: 32px;
        overflow: hidden;
        -webkit-transition: max-height 0.5s;
        transition: max-height 0.5s;
    }
    #cssmenu.expand ul {
        max-height: 900px;
    }
    }
#cssmenu > ul > li {
    border-right: 1px solid #000000;
    -moz-box-shadow: 1px 0 0 rgba(255, 255, 255, 0.2);
    -webkit-box-shadow: 1px 0 0 rgba(255, 255, 255, 0.2);
    box-shadow: 1px 0 0 rgba(255, 255, 255, 0.2);
    float: left;
    }
#cssmenu > ul > li.mobile {
    display: none;
    }
#cssmenu > ul > li.active {
    background: #444444;
    background: -moz-linear-gradient(#444444 0%, #323232 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #444444), color-stop(100%, #323232));
    background: -webkit-linear-gradient(#444444 0%, #323232 100%);
    background: linear-gradient(#444444 0%, #323232 100%);
    }
@media all and (max-width: 480px) {
    #cssmenu > ul > li {
        border-right: 0 none;
        -moz-box-shadow: 0 0 0 transparent;
        -webkit-box-shadow: 0 0 0 transparent;
        box-shadow: 0 0 0 transparent;
        display: block;
        float: none;
    }
    #cssmenu > ul > li.mobile {
        display: block;
    }
    #cssmenu > ul > li.mobile i {
        float: right;
        font-style: normal;
    }
    }
#cssmenu > ul > li:last-child {
    border-right: 0 none;
    -moz-box-shadow: 0 0 0 transparent;
    -webkit-box-shadow: 0 0 0 transparent;
    box-shadow: 0 0 0 transparent;
    -webkit-border-radius: 0 4px 4px 0;
    -moz-border-radius: 0 4px 4px 0;
    border-radius: 0 4px 4px 0;
    }
#cssmenu > ul > li:last-child ul {
    left: auto;
    right: 0;
    }
#cssmenu > ul > li.mobile {
    border-right: 0 none;
    -moz-box-shadow: 0 0 0 transparent;
    -webkit-box-shadow: 0 0 0 transparent;
    box-shadow: 0 0 0 transparent;
    }
#cssmenu > ul > li > a {
    margin: 0 0 2px 0;
    font-size: 12px;
    display: block;
    color: #ffffff;
    text-shadow: 0 1px 1px #000;
    }
#cssmenu > ul > li > a > span {
    display: block;
    padding: 6px 10px;
    font-weight: bold;
    }
#cssmenu > ul > li > a:hover {
    text-decoration: none;
    }
#cssmenu > ul > li.active {
    border-bottom: none;
    }
#cssmenu > ul > li.active > a {
    color: #fff;
    text-shadow: 0 1px 1px #000;
    }
/* Sub menu */
#cssmenu ul ul {
    background: #f9f9f9;
    border: 1px solid #cccccc;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    -moz-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.25);
    -webkit-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.25);
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.25);
    padding: 5px 12px;
    display: none;
    position: absolute;
    top: 33px;
    left: 0;
    width: 200px;
    z-index: 1;
    }
@media all and (max-width: 480px) {
    #cssmenu ul ul {
        position: relative;
        top: 0;
        width: 100%;
    }
    }
#cssmenu ul ul li {
    padding: 3px 0;
    }
#cssmenu ul ul a {
    color: #999999;
    display: block;
    font-size: 12px;
    font-weight: bold;
    }
#cssmenu ul ul a:hover {
    color: #444444;
    }
$(document).on('ready page:load', function() {
  // Your implementation here ...
});