javascript - 如何在JS中将数字转换为布尔值?
问题描述
我试图将数字转换为布尔值,
但我的 if 条件总是运行 else 块语句。
if ( !($(document).find($('.formSectionWrapper').length)) ) {
console.log('IF')
} else {
console.log('ElSE')
}
当长度为 0 时,它运行 else,当它大于 0 时,它再次运行 else 阻塞!我的错误是什么?
解决方案
只是改变
if(!($(document).find($('.formSectionWrapper').length)))
到
if(!($(document).find($('.formSectionWrapper')).length))
注意括号。
推荐阅读
- javascript - 如果一个对象的属性需要一个承诺值,如何创建一个对象
- amazon-sqs - 如何使用 Java SDK 以编程方式删除确认的 SNS 订阅(但不是主题)?
- gremlin - Neptune Gremlin - 如何通过 where count > 2 编写 group
- python - 为什么我不能从我的 github 存储库中读取 joblib 文件?
- android - 无法从 ViewModel 向用户显示协程错误消息
- ios - 获取 UIButtons 的 Size (x, y, width, height)
- linux - Linux上的cd(更改目录)命令
- google-classroom - 当 Google Classrom 为参加课程的教师列出 courseWork API 时收到 403
- angular - 如果隐藏元素,如何检测 Angular 中的屏幕尺寸是否发生变化?
- spring-integration - 没有数据源轮询的 MessageChannelPartionHandler 堆栈跟踪