美文网首页vue系列uni
js 最简单判断是否有值

js 最简单判断是否有值

作者: litielongxx | 来源:发表于2022-04-08 11:07 被阅读0次

当输入框存在''和0时,要区分是输入的0还是没有输入过


image.png

Boolean数字0为false,字符0为true。
只需要 Boolean(value+'')就可以区分了。
ps:同理还有??操作符号,有时可以省事。

undefined??2  //2  只有左侧为undefined时才会显示右边
0??2   //  0
''??2  // 0

相关文章

网友评论

    本文标题:js 最简单判断是否有值

    本文链接:https://www.haomeiwen.com/subject/brfysrtx.html