简体   繁体   English

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

[英]How to add exception in this jquery code?

How to add exception in this jquery code? 如何在此jQuery代码中添加异常?

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

this code is applying on all tables. 此代码适用于所有表。

but for specific pages i don't want strip effect. 但是对于特定的页面,我不希望出现剥离效果。

I've different body id on each page. 我在每个页面上都有不同的正文ID。

I want to know how to add exception for a id. 我想知道如何为ID添加例外。

$(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">
      });

David's solution works if you only have to filter for one ID. 如果您只需要过滤一个ID,David的解决方案就可以工作。 However, since you have several body IDs for which you don't want to use the script, you can use something like this: 但是,由于您不想使用该脚本有多个正文ID,因此可以使用以下代码:

$('body:not(#id1, #id2, #id3) tr:even').addClass('striped');
$('body[id!=nostrip] table tr:nth-child(even)').addClass("striped");

可以减少到

$('body[id!=nostrip] tr:even').addClass("striped");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM