jQuery:通过单击删除上一课 [英] jquery: remove previous class by clicking

查看:61
本文介绍了jQuery:通过单击删除上一课的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的问题,但我自己无法解决. 我有以下问题.

I've a very simple question but can't figure it out by myself. i've the following problem.

我有几个如下的列表项.

i've several list items like below.

<li></li>
            <li>
                <img src="images/persoon1.jpg" alt="persoon1">
                <div id="infoPersoon">
                    <h3>Jaap-Jan van der Gouw</h3>
                    <ul id="contactInfo">
                        <li class="label">T</li>
                        <li>070 31 31 066</li>
                        <li class="label">F</li>
                        <li>070 31 31 066</li>
                        <li class="label">M</li>
                        <li>070 31 31 066</li>
                    </ul>
                    <ul id="contactOpties">
                        <li class="email"><a href="#" class="active">Email</a></li>
                        <li class="publicaties"><a href="#">Publicaties</a></li>
                        <li class="vcard"><a href="#">Vcard</a></li>
                        <li class="meerinfo"><a href="#">Meer info</a></li>
                    </ul>
                </div>
            </li>
            <li></li>

问题是我想通过单击的当前列表添加一个类,并且当我单击到下一个列表项时,必须删除先前的活动"类.

the problem is that i want to add a class by the current list i clicked on, and when i clicked to the next list item, the previous class "active" must be remove.

我该如何解决这个问题.

how can i solve that problem.

推荐答案

最常见的方法是从具有以下标记的任何标签中删除活动类:

The most common approach is to remove the active class from any tag that has it like:

$(".active").removeClass("active");

将所有内容放在一起将是:

To put it all together would be:

$("li").click(function() {
    $(".active").removeClass("active");
    $(this).addClass("active");
});

这篇关于jQuery:通过单击删除上一课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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