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

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

相关文章
添加附近的小程序,一直显示系统繁忙
Iphone6 进入小程序显示空白页面,进不去小程序,小程序名称“悟空塑胶”
8月23日中午2点后,公众号报出系统繁忙?几小时设计数据!!!
手机微信收不到红包
开发者工具
随便看看
企业微信通讯录账号被管理员误/恶意删除,怎么办? 9568
问题? 9048
如何快速搭建抽奖助手小程序(无需代码知识) 6177
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 7472
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 6793
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 6128
如何解决渲染层网络错误Failed to load media? 17393
小程序找号找回 释放昵称? 3253
我的小程序广告主收入5301,实际进账4406,是怎么回事呀? 3108
删除部分微信用户个人数据的通知,怎么删除? 6381