How to negate code in quot;ifquot; statement block in JavaScript -JQuery like #39;if not then..#39;(如何否定“if中的代码JavaScript -JQuery 中的语句块,例如“如果不是那么..)
问题描述
例如,如果我想在 used 元素的父元素没有 ul
标签作为下一个元素的情况下做某事,我该如何实现呢?
For example if I want to do something if parent element for used element hasn't got ul
tag as next element, how can I achieve this?
我尝试结合使用 .not()
和/或.is()
没有成功.
I try some combination of .not()
and/or
.is()
with no success.
对 if else
块的代码求反的最佳方法是什么?
What's the best method for negate code of a if else
block?
我的代码
if ($(this).parent().next().is('ul')){
// code...
}
我想实现这个
伪代码:
if ($(this).parent().next().is NOT ('ul')) {
//Do this..
}
推荐答案
您可以使用逻辑非 !
运算符:
You can use the Logical NOT !
operator:
if (!$(this).parent().next().is('ul')){
或等效(见下面的评论):
Or equivalently (see comments below):
if (! ($(this).parent().next().is('ul'))){
有关详细信息,请参阅 MDN 的 逻辑运算符部分文档.
For more information, see the Logical Operators section of the MDN docs.
这篇关于如何否定“if"中的代码JavaScript -JQuery 中的语句块,例如“如果不是那么.."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何否定“if"中的代码JavaScript -JQuery 中的语句块,例如“如果不是那么.."


- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01