else if 里面 if判断验证没有问题就是一直不执行else中的语句这是什么问题?

小程序 文章 2022-02-11 11:00 866 0 全屏看文

AI助手支持GPT4.0

else if 里面 if判断验证没有问题就是一直不执行else中的语句这是什么问题?In else if, if there is no problem with the judgment verification, it means that the statement in the else is not executed all the time. What is the problem?

else if 里面 if判断验证没有问题就是一直不执行else中的语句这是什么问题?

 else if (this.data.Email != '') {

      if (!str.test(this.data.Email)) { // 判断邮箱格式是否有误 如果有误就提示用户请输入正确的邮箱

        wx.showToast({

          title: '请输入正确的邮箱',

          icon: 'none',

          duration: 2000

        })

      }

    }

判断没问题就是不执行else

Else if (this. Data. Email! = '') {if (! Str.test (this. Data. Email)) {/ / judge whether the email format is incorrect. If there is any error, prompt the user. Enter the correct email Wx. Showtoast ({Title: 'please enter the correct email', Icon: 'none', duration: 2000})}} judge that there is no problem, but do not execute else

回答:

小黎:

贴个完整的代码吧,没看到你else在哪儿

小勇童学🍊:else if (this.data.Email != '') {
      if (!str.test(this.data.Email)) { // 判断邮箱格式是否有误 如果有误就提示用户请输入正确的邮箱
        wx.showToast({
          title: '请输入正确的邮箱',
          icon: 'none',
          duration: 2000
        })
      }
    } else {
      wx.request({
        url: 'http://172.16.1.8:82/User/UpdateBaseUserInfo',
        method: 'POST',
        data: {
          "UserInfoID": app.globalData.ID,
          "RealName": this.data.RealName,
          "Sex": this.data.Sex,
          "Email": this.data.Email
        },
        dataType: 'json',
        header: {
          'content-type': 'application/json' // 默认值
        },
        //调用后台接口成功回调
        success: function (res) {
          console.log(res.data);
          if (res.data == 'True') {
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 2000
            })
          } else {
            wx.showToast({
              title: '保存失败',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    }
小勇童学🍊:else if (this.data.Email != '') {
      if (!str.test(this.data.Email)) { // 判断邮箱格式是否有误 如果有误就提示用户请输入正确的邮箱
        wx.showToast({
          title: '请输入正确的邮箱',
          icon: 'none',
          duration: 2000
        })
      }
    } else {
      wx.request({
        url: 'http://172.16.1.8:82/User/UpdateBaseUserInfo',
        method: 'POST',
        data: {
          "UserInfoID": app.globalData.ID,
          "RealName": this.data.RealName,
          "Sex": this.data.Sex,
          "Email": this.data.Email
        },
        dataType: 'json',
        header: {
          'content-type': 'application/json' // 默认值
        },
        //调用后台接口成功回调
        success: function (res) {
          console.log(res.data);
          if (res.data == 'True') {
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 2000
            })
          } else {
            wx.showToast({
              title: '保存失败',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    }
中式小面包:

1,走了else if

2,if 验证过不执行弹窗

3,代码执行结束

中式小面包:我猜你是想执行else if下面的else,整合下else if的判断,去掉里面的if
小勇童学🍊:里面的if必须要的  去掉了就做不了验证了
中式小面包:else if (this.data.Email != ‘’ && !str.test(this.data.Email) ) {...}
小勇童学🍊:如果邮箱格式输入有误就会执行弹窗 没有错误就不会执行  elseif 明明通过了  就是不执行else
中式小面包:进了else if,代码执行完就完了,没有else。
中式小面包:哪里else
小勇童学🍊:我写了else没执行  是不是elseif执行问了就不走else了
中式小面包:是
小勇童学🍊:我就是想实现又要有邮箱验证  又可以为空
小勇童学🍊:就是邮箱验证是正则验证  为空还是会有弹窗提示请输入正确的邮箱
中式小面包:!email || 验证邮箱(email)
Mr.Zhao:

如何知道没问题的?

小勇童学🍊:如果if验证有问题的话就会出现弹窗的
小勇童学🍊:不知道为啥就是一直困在里面出不去 就执行不了else
Mr.Zhao:执行else还是执行else if?
小勇童学🍊:else if
Mr.Zhao:
小勇童学🍊:执行啊 不为空就做判断验证邮箱格式问题  就是验证不为空格式验证通过了就是不执行else
Mr.Zhao:你到底想说啥,被你搞懵逼了
小勇童学🍊:我就是想做邮箱格式验证可以为空的目的
Mr.Zhao:if(条件) 不就行了,很迷,问题在哪
小勇童学🍊://保存用户编辑的信息
  preserve: function () {
    //姓名验证
    var reg = /^[u4E00-u9FA5uf900-ufa2d·s]{2,6}$/;
    //邮箱验证
    let str = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*.[a-zA-Z0-9]{2,6}$/;
    console.log('用户信息保存');
    if (this.data.RealName.length == 0 || this.data.RealName == '') {
      wx.showToast({
        title: '姓名不能为空',
        icon: 'none',
        duration: 2000
      })
    } else if (!reg.test(this.data.RealName)) {
      wx.showToast({
        title: '姓名格式有误请重新输入',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.Email != '') {
      if (!str.test(this.data.Email)) { // 判断邮箱格式是否有误 如果有误就提示用户请输入正确的邮箱
        wx.showToast({
          title: '请输入正确的邮箱',
          icon: 'none',
          duration: 2000
        })
      }
    } else {
      wx.request({
        url: 'http://172.16.1.8:82/User/UpdateBaseUserInfo',
        method: 'POST',
        data: {
          "UserInfoID": app.globalData.ID,
          "RealName": this.data.RealName,
          "Sex": this.data.Sex,
          "Email": this.data.Email
        },
        dataType: 'json',
        header: {
          'content-type': 'application/json' // 默认值
        },
        //调用后台接口成功回调
        success: function (res) {
          console.log(res.data);
          if (res.data == 'True') {
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 2000
            })
          } else {
            wx.showToast({
              title: '保存失败',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    }
    app.globalData.RealName = this.data.RealName
  },
小勇童学🍊:我把全部代码贴出来你看一下
Mr.Zhao:没看懂想说啥
小勇童学🍊:执行完elseif else不执行了
Mr.Zhao:不执行啥?麻烦你框起来可以吗  很蒙蔽的

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
小店升级小商店/?
怎么改小程序名字?
小程序开发时 如何把data里的数据转换成时间格式?
web-view里h5页面可以打开其他小程序吗?
赶紧开放修改标题的功能吧?求求了
随便看看
注册服务号提示“系统繁忙,请稍后重试”,试了N多次了!怎么办吖? 542
二维码一时可以一时不行? 394
获取用户基本信息不再输出昵称和头像,那么有没有新的方式可以获取呢? 482
frameset 提示不支持? 429
获取用户基本信息(UnionID机制)没有昵称? 817
微信支付申请特约商户时,出现商户名称与营业执照注册号不匹配,如何解决? 3637
微信搜一搜中出现的诋毁我个人的相关搜索词怎么处理? 536
微信关注后回调接口获取不到用户头像和昵称 1187
getuserphonenumber获取手机号接口真机可用,发布后报错? 3371
小程序的code可以无限制获取吗? 1230