如何否定“if”中的代码声明 [英] How to negate code in "if" statement

查看:98
本文介绍了如何否定“if”中的代码声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我想要做的事情,如果使用的元素的父元素没有 ul 作为下一个元素我应该添加到此代码中?不知怎的,我尝试了一些 .not()和/或
.is()的组合,但是它们失败了对我来说。

For example if I want to do something if parent element for used element hasn't got ul as next element what should I add to this code? Somehow I try some combination of .not() and/or .is() but they fail for me.

所以有人可能知道之后否定代码的最佳方法是

if ($(this).parent().next().is('ul')){
   // code...
}


推荐答案

你可以使用逻辑NOT 运算符:

You can use the Logical NOT ! operator:

if (!$(this).parent().next().is('ul')){

或等效(参见下面的评论):

Or equivalently (see comments below):

if (! ($(this).parent().next().is('ul'))){

有关详细信息,请参阅逻辑运算符部分。

For more information, see the Logical Operators section of the MDN docs.

这篇关于如何否定“if”中的代码声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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