javascript - 刀片模板 Laravel 中的不等式值错误
问题描述
我目前在我的 Blade.php (Laravel) 页面上使用 javascript 代码,我有一个奇怪的错误:我的 != 不被接受:
if({{ $CurrentProduct->disposable_quantity }} != null) {
if (newQty > {{ $CurrentProduct->disposable_quantity }}) {
$('input[name="quantity"]').val({{ $CurrentProduct -> disposable_quantity }});
}
}
如果我放一个 == 我的代码不再包含错误。我不明白
解决方案
如果你真的想确认一个变量不是null
而且不是empty string
特别的,你会写:
if({{ $CurrentProduct->disposable_quantity }} !== null) {
// do something
}
我更改了您的代码以检查类型是否相等(!==
| ===
)。
您还可以使用以下简单代码:
if(Boolean({{ $CurrentProduct->disposable_quantity }} )){
// do something
}
注意:直观上为empty
, 0
an empty string
, null
, undefined
, andNaN
的值变为假
其他值变为真
推荐阅读
- speech-to-text - Google-cloud-speech“自动检测语言”功能仅检测一种语言
- javascript - 如何使用 npm 链接修复 Angular 库中的“未找到模块”错误?
- javascript - 切换类添加类但不删除它
- google-cloud-print - 如何在没有浏览器提示的情况下使用 aouth2 访问谷歌云打印?
- c++ - 尝试初始化结构向量时出现编译错误
- r - 将 20 GB csv 文件加载到 R 中的最佳方法是什么?
- python - 为 python3.7 Ubuntu 18.04 安装 pandas
- unity3d - 轻量级渲染管线弄乱了物体的纹理
- vue.js - Vue路由器链接按钮组件
- angular - Angular Protractor 如何使用 findElements(by.tagName) 获取 tr 中的所有 td