Bry*_*yan 1 javascript css jquery
早上,
我一定要问谷歌所有错误的问题,因为我找不到类似的东西.
我有一个标准的导航列表,但我正在使用页面跳转,因为我想要一个网页.
<ul>
<li><a href="#livestream">Livestream</a></li>
<li><a href="#media">Media</a></li>
<li><a href="#crew">Crew</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
但我不能为我的生活弄清楚如何在使用页面跳转时使class ="current".我试过这个jquery,因为它似乎是我正在寻找的,但它没有做任何事情.我不认为它适用于#links.
有任何想法吗?
如果要将当前类添加到a已单击的内容中,可以像这样完成:
// Wait for the DOM to be ready
$(function(){
// Add click-event listener
$("li a").click(function(){
// Remove the current class from all a tags
$("li a").removeClass("current");
// Add the current class to the clicked a
$(this).addClass("current");
});
});
Run Code Online (Sandbox Code Playgroud)