1
請幫助我的。我使用帶有寶石渦輪的rails5。我的導航菜單代碼:事件turbolinks:負載工作奇怪
<div id="templatemo_menu" class="ddsmoothmenu">
<ul>
<li><a class="level_0 index" href="/">Главная</a></li>
<li><a class="level_0 about" href="/pages/about">О нас</a></li>
<li><a class="level_0 portfolio" href="/type_works">Портфолио</a>
<ul>
<li><a class="level_1" href="/works?type_work_id=1">Corporate Metrics Liaison</a></li>
<li><a class="level_1" href="/works?type_work_id=2">Chief Solutions Planner</a></li>
<li><a class="level_1" href="/works?type_work_id=3">Central Applications Architect</a></li>
<li><a class="level_1" href="/works?type_work_id=4">Global Metrics Executive</a></li>
</ul>
</li>
<li><a class="level_0 blog" href="/blog_articles">Блог</a></li>
<li><a class="level_0 contact" href="/contact_messages/new">Контакт</a></li>
</ul>
<br style="clear: left">
</div>
我需要點擊'.about'後,BODY背景變爲紅色。但是現在單擊BODY背景後沒有改變。它的問題。
我試圖解決:
var menuActivePunkt = function(){
var pathname = location.pathname,
pathnameList = pathname.split('/'),
slug1 = pathnameList[1],
slug2 = pathnameList[2];
console.log('slug1', slug1);
console.log('slug2', slug2);
$('#templatemo_menu a').removeClass('selected').on('click', function() {
if(slug1 == 'pages' && slug2 == 'about') {
//$('.index').addClass('selected');
$('body').css({'background': 'red'});
};
});
}
$(document).on('turbolinks:load', function() {
menuActivePunkt();
})
您是否在'app/assets/javascripts/application.js'中添加了'// = require turbolinks' – VKatz