如何将课程更改为一旦点击就激活 [英] How to change a class to active once clicked

查看:102
本文介绍了如何将课程更改为一旦点击就激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < section class =top-bar-section> 
< ul class =adjust>
< li class =active>< a href =#>主页< / a>< / li>
< li class =>< a href =#contact> CONTACT< / a>< / li>
< li class =>< a href =#> BLOG< / a>< / li>
< li class =>< a href =#> SHOP< / a>< / li>
< / ul>
< / section>

基本上我希望班级在点击联系人链接时变为激活状态。这将页面移动到页脚。你们知道我该怎么做吗?
我在这里尝试了jquery的东西,但由于某种原因,我似乎无法让它工作。



我使用Foundation 5.0.3,如果有帮助的话: )

解决方案

您可以使用以下基本类型:

<$ p $ ()函数(){
$(this).addClass('active')。siblings('li')。removeClass() 'active');
});

示例


I so far have this code:

<section class="top-bar-section">
<ul class="adjust">
<li class="active"><a href="#">HOME</a></li>
<li class=""><a href="#contact">CONTACT</a></li>
<li class=""><a href="#">BLOG</a></li>
<li class=""><a href="#">SHOP</a></li>
</ul>      
</section>

And basically I would like the class to change to active when I click on the "contact" link. This moves the page down to the footer. Do you guys know how I could do this? I tried that Jquery thing on here but for some reason I cannot seem to get it to work.

I am using Foundation 5.0.3 if that helps :)

解决方案

You could use something basic like this:

$('.adjust > li').click(function(){
    $(this).addClass('active').siblings('li').removeClass('active');
});

EXAMPLE HERE

这篇关于如何将课程更改为一旦点击就激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆