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

小程序 文章 2022-02-11 11:00 748 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群

相关文章
审核一直都是机器人驳回,希望人工干预一下?
点击会穿透到picker-view下方的input上?求解决
微信模板消息停用了吗?
小程序上传的开发版本能否关联企业微信获得AgentId和Secret?
域名已通过ICP备案(按要求新域名已过24小时),但是在小程序配置域名时还是提示未通过?
随便看看
现在ios小程序涉及虚拟支付可以吗?我看有的小程序iOS允许虚拟支付? 624
onShareAppMessage 好友转发,自己打开有内容,别人打开是空的,具体怎么解决? 1329
怎么从前端上传布尔值到云数据库? 274
onload里面的参数这样写是什么意思? 748
小程序测试号和小游戏测试号有什么作用? 1916
小程序注册不了,可不可以帮帮我? 317
scroll-view横向滚动最后一个盒子的背景颜色为什么铺不满,麻烦大佬解惑一下? 445
JSAPI支付用户成功,但是我们没有接收到回调 779
服务端接口API【security.msgSecCheck】的检测形同虚设? 555
企业注册的小程序为什么无权使用手机号授权功能? 384