jquery .not()无效 [英] jquery .not() not working

查看:72
本文介绍了jquery .not()无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在每个实例上发生一些事情,除非有一个禁用的类,但.not()似乎不起作用。这是我的简短版本:

I'm trying to have something happen on every instance except where there is a disabled class, but .not() doesn't seem to work. Here is a short version of what I have:

if($(this).not('.Disabled')){
     -Do Something-
}

但是,如果我将其反转,即

However, if I reverse it, i.e.

if($(this).is('.Disabled')){
     -Do Something-
}

然后is将对Class类的元素起作用
有点困惑从哪里开始。

then the "is" will work on an element with the class of "Disabled" Kind of confused where to go from here.

推荐答案

你假设不是是彼此的对立面。事实上,他们不是。 not()将返回一个jQuery对象,而 将返回一个布尔值,指示是否至少有一个项目在jQuery对象中执行它会遇到你传递它的选择器。

You're assuming that is and not are opposites of each other. In fact, they aren't. not() will return a jQuery object, while is will return a boolean value indicating whether or not at least one item in the jQuery object it is executed against meets the selector you pass it.

以下内容应该完成你正在尝试的内容:

The following should accomplish what you're attempting:

if(!$(this).is('.Disabled')){-Do Something- }

这篇关于jquery .not()无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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