zoukankan      html  css  js  c++  java
  • 微信小程序--获取form表单初始值提交数据

    <form bindsubmit="formSubmit">
        <view class="txt">
          <view class="ima"></view>
          <view class="txt2">姓名</view>
          <input placeholder="请输入姓名" maxlength="10" class="txt3" value="{{mem_name}}" bindchange="name" name="name2"/>
        </view>
        <view class="txt">
          <view class="ima"></view>
          <view class="txt2">身份证号</view>
          <input type="idcard" placeholder="请输入身份证号码" class="txt3"   value="{{mem_IDnum}}" bindchange="ID_num" maxlength="18" name="ID_num2"/>
        </view>
        <view style="clear:both"></view>
        <button class="btn" form-type="submit" hover-class="none">完成</button>
      </form>
    page({
    name: function (e) {   //获取input输入的值
        var that = this;
        that.setData({
          name: e.detail.value
        })
      },
      ID_num: function (e) {    //获取input输入的值
        var that = this;
        that.setData({
          ID_num: e.detail.value
        })
        var id_num = that.data.ID_num
        if (!(id_num.length === 15 || id_num.length === 18)) {
          wx.showToast({
            title: '请输入15或18位数身份证号码',
            image: '../Image/error.png',
            duration: 2000
          })
        }
      },
    
    formSubmit: function (e) {
        var that = this;
        var tokend = wx.getStorageSync('tokend')
        var name2 = e.detail.value.name2;         //获取input初始值
        var ID_num2 = e.detail.value.ID_num2;    //获取input初始值
        var name = that.data.name ? that.data.name : name2    //三元运算,如果用户没修改信息,直接提交原来的信息,如果用户修改了信息,就将修改了的信息和未修改过的信息一起提交
        var ID_num = that.data.ID_num ? that.data.ID_num : ID_num2
        wx.request({
          method: 'POST',
          url: 'https://....?token=' + tokend, //接口地址
          data: {
            'name': name,
            'ID_num': ID_num
          },
          header: { 'content-type': 'application/json' },
          success: function (res) {
            wx.showToast({
              title: '资料修改成功',
              image: '../Image/suess.png',
              duration: 2000
            })
            setTimeout(function () {
              wx.switchTab({
                url: '../index/index',
              })
            }, 2000)
    
          },
          fail: function (res) {
            console.log('cuowu' + ':' + res)
          }
        })
      },
    })
  • 相关阅读:
    将数据保存在线程中
    OpenSmtp 的代码修正,支持中文和HTTP代理连接
    枚举.NET的基本类型
    通过HTTP代理连接到目的的协议
    程序出现了异常:应用程序无法启动,因为应用程序的并行配置不正确
    关于最近的一篇文章
    检测TextBox的回车键事件
    程序跳过trycatch地崩溃
    给程序加上UAC控制的几个链接
    Sql Server附加数据库的时候出现Operating system error 5: "5(Access is denied.)" 的错误
  • 原文地址:https://www.cnblogs.com/JinQing/p/6693907.html
Copyright © 2011-2022 走看看