本文介绍了如何否定“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 中的语句块,例如“如果不是那么.."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)