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

小程序 文章 2021-04-06 10:42 371 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群

相关文章
小程序通过webview访问的外链,如果外链的网页页面有需要播放的视频,这个有没有什么资质要求?
小程序商场是空白的,怎么添加商品?
wx.pageScrollTo无效?页面无使用scroll-view ?
小程序真机调试没有问题,审核后发布上架安卓端没问题,但是ios端点击无效果?
微信支付服务商授权问题
随便看看
微信公众号免300认证教程 5190
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 4496
小程序广告组件通过审核,但是小程序内没有显示广告? 4471
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8528
问题? 8250
如何快速搭建抽奖助手小程序(无需代码知识) 5309
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6576
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5865
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5524
如何解决渲染层网络错误Failed to load media? 16768