gpt4 book ai didi

jquery - 如何在此 jquery 代码中添加异常?

转载 作者:太空宇宙 更新时间:2023-11-03 21:00:52 25 4
gpt4 key购买 nike

如何在这个 jquery 代码中添加异常?

$(function() {
$("table tr:nth-child(even)").addClass("striped");
});

此代码适用于所有表。

但对于特定页面我不想要 strip 效果。

我在每个页面上都有不同的 body id。

我想知道如何为一个 id 添加异常(exception)。

$(function() {
$("table tr:nth-child(even)").addClass("striped");
//I want to add exception to not to add striped class to only to page with <body id="nostrip">
});

最佳答案

如果您只需过滤一个 ID,David 的解决方案就可以使用。但是,由于您有几个不想使用脚本的正文 ID,您可以使用如下内容:

$('body:not(#id1, #id2, #id3) tr:even').addClass('striped');

关于jquery - 如何在此 jquery 代码中添加异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2866177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com