点击链接jquery时更改活动li [英] change active li when clicking a link jquery

查看:70
本文介绍了点击链接jquery时更改活动li的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作菜单,点击时更改类。

I want to make a menu, and change the class when clicking.

当我点击li没有 class =active时,我想要jquery添加一个在空的< li> >上移除它,并从icesli中移除它。

When i click on the "li" with no class="active", i want jquery to add a class on the empty <li> and remove it from the othes "li".

<li class="active"><a href="javascript:;" onclick="$.data.load(1);">data</a></li>
<li><a href="javascript:;" onclick="$.data.load(2);">data 2</a></li>

有人可以帮我吗? :)

can somebody help me ? :)

推荐答案

我想你的意思是这样的:

I think you mean this:

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

这篇关于点击链接jquery时更改活动li的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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