html:{
<view class='tj'>
<form bindsubmit="formSubmit">
<view class='title'>丫丫上门服务</view>
<view class='box'><label>姓名:</label> <input type='text' name='xm' value='' /> <view class='clear'></view></view>
<view class='box'><label>联系方式:</label> <input type='text' name='lxfs' value='' /> <view class='clear'></view> </view>
<view class='box'><label>需求:</label> <input type='text' name='xq' value='' /> <view class='clear'></view></view>
<view class='box'><label>小区名字:</label> <input type='text' name='xqmz' value='' /> <view class='clear'></view></view>
<button formType="submit">提交</button>
</form>
</view>
}
index.js代码
Page({
formSubmit: function (e) {
// var info = e.detail.value
if (e.detail.value.xm.length == 0 || e.detail.value.xq.length == 0 || e.detail.value.lxfs.length == 0 || e.detail.value.xqmz.length == 0) {
wx.showModal({
title: '姓名或联系方式或需求或小区名字不得为空!',
content:'很棒棒哟',
})
} else if (e.detail.value.lxfs.length != 11){
wx.showToast({
title: '请输入11位手机号码!',
icon: 'loading',
duration: 1500
})
setTimeout(function () {
wx.hideToast()
}, 2000)
}else{
wx.request({
url: app.globalData.http + '/Wechat/apply', //仅为示例,并非真实的接口地址
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
method:'POST',
data:{xm:e.detail.value.xm,lxfs:e.detail.value.lxfs,xq:e.detail.value.xq,xqmz:e.detail.value.xqmz},
success: function (res) {
if (res.data.status == 0) {
wx.showToast({
title: res.data.info,
icon: 'loading',
duration: 1500
})
} else {
wx.showToast({
title: res.data.info,//这里打印出登录成功
icon: 'success',
duration: 1000
})
}
}
})
}
},
如有不懂可查看原网站http://www.jb51.net/article/102875.htm