链接“兄弟姐妹”和“不”方法

发布于 2024-12-20 02:45:24 字数 290 浏览 5 评论 0原文

我目前正在尝试链接 .siblings 和 .not 方法:

$(nextBanner).siblings(".banner").not(".active").hide();

但它不起作用 – 有人知道如何定位一组兄弟姐妹并排除具有特定类别的兄弟姐妹吗?

您可以在这里观看我的示例:http://jsfiddle.net/timkl/56Mqg/25/

I'm currently trying to chain the .siblings and .not method:

$(nextBanner).siblings(".banner").not(".active").hide();

But it doesn't work – does anyone know how to target a set of siblings and exclude the ones that have a particular class?

You can watch my example here: http://jsfiddle.net/timkl/56Mqg/25/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

舞袖。长 2024-12-27 02:45:25

试试这个

$('.banner').hide();
$(prevBanner).show().addClass("active");

$('.banner').hide();
$(nextBanner).show().addClass("active");

你的代码有一些缺陷,我已经在你的小提琴中纠正了这些缺陷。看看它。

工作演示

Try this

$('.banner').hide();
$(prevBanner).show().addClass("active");

and

$('.banner').hide();
$(nextBanner).show().addClass("active");

Your code have few flaws which I have corrected in your fiddle. Take a look at it.

Working demo

南城旧梦 2024-12-27 02:45:24

尝试:

$(nextBanner).siblings(".banner:not(.active)").hide();

Try:

$(nextBanner).siblings(".banner:not(.active)").hide();
芸娘子的小脾气 2024-12-27 02:45:24

也尝试一下

$(prevBanner).siblings(".banner:not(this)").hide();
// and
$(nextBanner).siblings(".banner:not(this)").hide();

,您可以执行 $(".banner").hide() 然后 $(nextBanner).show();

try this

$(prevBanner).siblings(".banner:not(this)").hide();
// and
$(nextBanner).siblings(".banner:not(this)").hide();

also you could do a $(".banner").hide() and then $(nextBanner).show();

橘寄 2024-12-27 02:45:24

您只是忘记删除 active 类。我对你的例子做了一点修改(而且我根本不使用 siblings() ),所以它可以工作:http://jsfiddle.net/56Mqg/27/

you simply forgot to remove the active-class. i modified you example just a tiny bit (and i don't use siblings() at all) so it works: http://jsfiddle.net/56Mqg/27/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文