码迷,mamicode.com
首页 > 微信 > 详细

表单提交(微信小程序)

时间:2017-12-09 15:47:41      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:信息   idcard   this   姓名   tps   号码   修改   card   gets   

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

表单提交(微信小程序)

标签:信息   idcard   this   姓名   tps   号码   修改   card   gets   

原文地址:http://www.cnblogs.com/weiwentaweb/p/8011548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!