if function里面 && 和 || 竟然出现一样的答案?

小程序 文章 2021-04-06 10:42 354 0 全屏看文

AI助手支持GPT4.0

if function里面 && 和 || 竟然出现一样的答案?In the if function, && and || appear to have the same answer?

if function里面 && 和 || 竟然出现一样的答案?
    if (this.data.inputValue1!='' || this.data.inputValue2!='' || this.data.inputValue3!='' || this.data.inputValue4!='') {      this.setData({        clsStatus: false      })    } else {      this.setData({        clsStatus: true      })    }以上就是我纠结了一晚上的代码。上面的代码是成功使用的。如果任意一个inputValue不为空,都会变成false。但是问题是我希望设置,如果任意一个inputValue为空,变成false。系统则不让我过。我也不知道什么原因。我就是将上面的 || 换成 &&, 但是结果竟然还是一样的。太奇怪了。 不知道别人有没有遇到一样的问题?谢谢大家的时间!

    if ( this.data.inputVal ue1!='' ||  this.data.inputValue2 !='' ||  this.data.inputValue3 !='' ||  this.data.inputValue4 !='') {       this.setData ({        clsStatus: false      })    } else {       this.setData (clsstatus: true)} that's what I've been struggling with all night Code. The above code was used successfully. If any inputvalue is not empty, it will become false. But the problem is that I want to set it to false if any inputvalue is empty. The system won't let me. I don't know why. I just changed the |, but the result was the same. It's strange. I don't know if other people have the same problem? Thank you for your time! 

回答:

青寒:

xieyao.

是要实现“如果任意一个inputValue为空,变成false”这个需求?

if (this.data.inputValue1=='' || this.data.inputValue2=='' || this.data.inputValue3=='' || this.data.inputValue4=='') {      this.setData({        clsStatus: false      })    } else {      this.setData({        clsStatus: true      })    }


Made in.内江:
const {inputValue1, inputValue2, inputValue3, inputValue4} = this.datathis.setData({   clsStatus: inputValue1 && inputValue2 && inputValue3 && inputValue4})


吃鱼先生:

你期望的"空"指的是啥?null还是空字符串还是?

建议尝试使用"==="或者"!==",

另,建议你代码精简成

this.setData({  clsStatus: !(this.data.inputValue1!='' || this.data.inputValue2!='' || this.data.inputValue3!='' || this.data.inputValue4!='')})


-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
wx.getLocalIPAddress is not a function 为什么?
scroll-view所有苹果手机以及pc端的小程序都出现内容重叠的问题,怎么解决?
现在审核全靠碰审核员的心情吗?
谁有node.js安装包?下载太慢了?
微信商户提示涉嫌交易异常,申诉通过后,仍然不能支付,希望官方大佬给看一下。万分感谢。
随便看看
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8364
问题? 7481
如何快速搭建抽奖助手小程序(无需代码知识) 5159
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6217
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5730
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5300
如何解决渲染层网络错误Failed to load media? 16647
小程序找号找回 释放昵称? 2593
我的小程序广告主收入5301,实际进账4406,是怎么回事呀? 2569
删除部分微信用户个人数据的通知,怎么删除? 5625