收藏
回答

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。系统则不让我过。我也不知道什么原因。
我就是将上面的 || 换成 &&, 但是结果竟然还是一样的。
太奇怪了。 不知道别人有没有遇到一样的问题?
谢谢大家的时间!
回答关注问题邀请回答
收藏

4 个回答

  • 睡前原谅一切
    睡前原谅一切
    2021-04-06
    const {inputValue1, inputValue2, inputValue3, inputValue4} = this.data
    this.setData({
       clsStatus: inputValue1 && inputValue2 && inputValue3 && inputValue4
    })
    


    2021-04-06
    有用 2
    回复 6
    查看更多(1)
  • 浪花骑士
    浪花骑士
    2021-04-06

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

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

    另,建议你代码精简成

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


    2021-04-06
    有用 1
    回复 3
  • 青寒
    青寒
    2021-04-06

    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
          })
        }
    


    2021-04-06
    有用 1
    回复 1
    • 刘柱华
      刘柱华
      2021-04-16
      谢谢你的答案,第一次发问题,让你困惑不好意思。 是这个意思。
      2021-04-16
      回复
  • 久安
    久安
    发表于小程序端
    2021-04-15

    const (inputValue1,inputValue2,inputValue3,inputValue4) =this.datathis. setData fclsStatus inputValue1 && inputValue2 && inputValue3 && inputValue4

    2021-04-15
    有用
    回复 1
    • 刘柱华
      刘柱华
      2021-04-16
      谢谢你的答案!
      2021-04-16
      回复
登录 后发表内容
问题标签