jQuery“活动"的课堂作业 [英] jQuery "active" class assignment

查看:99
本文介绍了jQuery“活动"的课堂作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要完成的所有工作都是能够获得一个无顺序的链接列表,在其中单击该链接,父列表项被分配为活动"类.在该列表中单击另一个链接后,它会检查是否已分配活动",将其从该列表项中删除,然后将其添加到最近单击的链接父列表项中.

All I am trying to accomplish is to be able to have an unordered list of links in which one is clicked, the parent list item is assigned the class "active." Once another link is clicked within that list, it checked to see if "active" is assigned, remove it from that list item, and add it to the most recent clicked links parent list item.

示例:

第一步-用户单击链接我是链接2"

Step One - User has clicked the link "I am link two"

<ul>
<li><a href="#">I am link one</a></li>
<li class="active"><a href="#">I am link two</a></li>
</ul>

第二步-用户现在单击链接我是链接一"

Step Two - User has now clicked the link "I am link one"

<ul>
<li class="active"><a href="#">I am link one</a></li>
<li><a href="#">I am link two</a></li>
</ul>

很简单,但是我打败了我.

Pretty simple, but man I beat me up.

推荐答案

假设:UL元素具有类"linksList".

Assumption: the UL element has the class 'linksList'.

$('.linksList li a').click(function()
{
  $('.linksList li').removeClass('active');
  $(this).parent().addClass('active');
});

这篇关于jQuery“活动"的课堂作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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