简体   繁体   English

与not()函数相反

[英]Opposite of not() function

I have a simple question, I've the following lines which equals to not active links : 我有一个简单的问题,以下几行内容等同于无效链接

$links.not($active).each(function() 
{
     //Do sth...
});

what is the opposite of the .not(...) function in JavaScript? JavaScript中.not(...)函数的反义词是什么? because I need to know the active links, Any ideas !? 因为我需要知道活动的链接,有什么想法!?

This is jQuery, not JavaScript. 这是jQuery,而不是JavaScript。 The opposite of .not is .filter . 的相反.not.filter

您正在寻找.filter() ,它返回仅包含匹配元素的子集。

Using $links.not($active) creates a collection with the elements from $links except the elements in $active . 使用$links.not($active)使用$links的元素(除了$active的元素$links.not($active)创建一个集合。

To get the active links, just use the $active object: 要获得活动链接,只需使用$active对象:

$active.each(function() 
{
  //Do sth...
});

The opposite of not in programming is often named is 相反not编程通常命名is

http://api.jquery.com/is/ http://api.jquery.com/is/

However this will return boolean true of false so in your case you'll be wanting filter 但是,这将返回布尔值true为false,因此在您的情况下,您需要filter

http://api.jquery.com/filter/ http://api.jquery.com/filter/

Example: 例:

$links.filter('.onlyThisClass').each(function() 
{
     //Do sth...
});

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

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