我有一个简单的 jquery 函数,可以在标题中的导航中添加和删除“活动”类:
$(document).ready(function () {
$('ul.right li').click(function() {
$("ul.right li.active").removeClass("active");
$(this).addClass('active');
});
});
只要我的链接看起来像这样,它就可以工作:
<li><%= link_to "people", "#" %></li>
但是,一旦我将其更改为:
<li><%= link_to "people", people_path %></li>
它为那个链接中断,但继续在其他存根链接上工作。
我很困惑。
** * ** * ** * ** * ** * ** *服务器输出* ** * ** * ** * ** * ** * ** * *
在 2013-09-15 13:08:45 -0500 开始 GET "/news" for 127.0.0.1 由 StaticPagesController#news 作为 HTML 弃用警告处理:Relation#all 已弃用。如果你想预先加载一个关系,你可以调用#load(例如Post.where(published: true).load
)。如果要从关系中获取记录数组,可以调用#to_a(例如Post.where(published: true).to_a
)。(从 /Users/jameson/Documents/projects/jemisonmetals/app/controllers/static_pages_controller.rb:6 的新闻中调用) Post Load (0.3ms) SELECT posts
.* FROM posts
ORDER BY created_at DESC Rendered layouts/_wispy.html.erb (0.1 ms) 加载后 (0.3ms) SELECT posts
.* FROMposts
ORDER BY created_at DESC LIMIT 5 在 layouts/application 中渲染 static_pages/news.html.erb (2.5ms) Rendered layouts/_header.html.erb (0.2ms) Rendered layouts/_footer.html.erb (0.2ms) 完成 200 OK in 14 毫秒(查看:12.4 毫秒 | ActiveRecord:0.6 毫秒)
2013-09-15 13:08:45 -0500 开始 GET "/assets/application.css?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/vendor/custom.modernizr.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/posts.css?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation_and_overrides.css?body=1" for 127.0.0.1
2013 年 9 月 15 日 13:08:45 -0500 开始为 127.0.0.1 获取“/assets/app.css?body=1”
2013-09-15 13:08:45 -0500 开始 GET "/assets/static_pages.css?body=1" for 127.0.0.1
在 2013-09-15 13:08:45 -0500 开始 GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.js?body=1" for 127.0.0.1
在 2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.alerts.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.clearing.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.cookie.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.dropdown.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.forms.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.joyride.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.magellan.js?body=1" for 127.0.0.1
在 2013-09-15 13:08:45 -0500 开始 GET "/assets/jquery.js?body=1" for 127.0.0.1
2013 年 9 月 15 日 13:08:45 -0500 开始为 127.0.0.1 获取“/assets/logo.png”
2013-09-15 13:08:45 -0500 开始为 127.0.0.1 获取“/assets/wispy.png”
2013-09-15 13:08:45 -0500 开始为 127.0.0.1 获取“/assets/logo-footer.png”
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.orbit.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.reveal.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.section.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.topbar.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.interchange.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.placeholder.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.tooltips.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/foundation.abide.js?body=1" for 127.0.0.1
2013-09-15 13:08:45 -0500 开始 GET "/assets/foundation/index.js?body=1" for 127.0.0.1
2013 年 9 月 15 日 13:08:45 -0500 开始为 127.0.0.1 获取“/assets/app.js?body=1”
2013 年 9 月 15 日 13:08:45 -0500 开始为 127.0.0.1 获取“/assets/posts.js?body=1”
2013-09-15 13:08:45 -0500 开始 GET "/assets/static_pages.js?body=1" for 127.0.0.1
在 2013-09-15 13:08:45 -0500 开始 GET "/assets/application.js?body=1" for 127.0.0.1
我看到了问题:
活动类被短暂地添加到 li 标记中,但随后页面加载并消失。单击存根链接时,没有页面刷新,这就是它们起作用的原因。
我在 _header.html.erb 部分中有标题代码,并从应用程序布局中调用它。