首页 > 解决方案 > 如何在JS中将数字转换为布尔值?

问题描述

我试图将数字转换为布尔值,
但我的 if 条件总是运行 else 块语句。

if ( !($(document).find($('.formSectionWrapper').length)) ) {
   console.log('IF')
} else {
   console.log('ElSE')
}

当长度为 0 时,它运行 else,当它大于 0 时,它再次运行 else 阻塞!我的错误是什么?

标签: javascriptjquery

解决方案


只是改变

if(!($(document).find($('.formSectionWrapper').length)))

if(!($(document).find($('.formSectionWrapper')).length))

注意括号。


推荐阅读