您现在的位置是:网站首页> 编程资料编程资料
微信小程序实现表单验证源码_javascript技巧_
2023-05-24
293人已围观
简介 微信小程序实现表单验证源码_javascript技巧_
本文实例为大家分享了微信小程序实现表单验证的具体代码,供大家参考,具体内容如下
效果图

点击预约设计弹出表单

城市,面积不能输入,只能选择

点击位置获取当前定位
源码:
Wxml
{{designerDetail.name}} {{designerDetail.honour}} 案例作品 预约设计 预约量房
js
// pages/designerList/designerDetail.js //获取应用实例 const app = getApp() Page({ /** * 页面的初始数据 */ data: { urlhttp: app.d.hostImg,//图片路径参数 designerDetail: {}, userlocation: '',//工程位置 acreagelist: ["60㎡以下", "60㎡-70㎡", "70㎡-100㎡", "100㎡以上"],//面积数组 userZoneList:[],//城市列表 price:0, dialogHidden:true, orderType:'',//预约类型 index: '',//面积下标 index2: '',//城市下标 btnStatus:true, designerid:'',//设计师id }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; var id = options.id; that.setData({ designerid:id, }) console.log(id) wx.showNavigationBarLoading(); wx.request({ url: app.d.ceshiUrl + 'home.designerDetail', data: { "id": id, }, success: function (res) { console.log(res) var res = res.data; that.setData({ designerDetail: res, }) wx.hideNavigationBarLoading(); } }) wx.request({ url: app.d.ceshiUrl + 'home.getService', success: function (res) { console.log(res) var res = res.data; that.setData({ userZoneList: res, }) wx.hideNavigationBarLoading(); } }) //支付金额 wx.request({ url: app.d.ceshiUrl + 'home.calc', success: function (res) { console.log(res) var res = res.data; that.setData({ price: res.price, }) } }) }, //选择所在区域 getLocation: function (e) { var that = this; wx.chooseLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success: function (res) { var latitude = res.latitude var longitude = res.longitude console.log(res) that.setData({ userlocation: res.name, latitude: latitude, longitude: longitude, }) } }) }, //所在城市选择 bindPickerzone: function (e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ index2: e.detail.value }) }, //房屋面积选择 bindPickerChange: function (e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ index: e.detail.value }) }, //图片预览 bindpreviewImage: function (e){ var that = this; console.log(e.currentTarget.id) var index = e.currentTarget.id; var picslist = that.data.designerDetail.pics; for (var i in picslist) { picslist[i] = that.data.urlhttp + picslist[i]; } wx.previewImage({ current: picslist[index], // 当前显示图片的http链接 urls: picslist // 需要预览的图片http链接列表 }) }, orderTap: function (e) { var that = this; console.log(e) that.setData({ orderType: e.target.dataset.type, dialogHidden: false, }) }, closeTap: function () { var that = this; that.setData({ dialogHidden: true, }) }, formSubmit: function (e) { var that = this; console.log(e.detail); var value = e.detail.value; var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;//电话校验 var acreage = that.data.acreagelist[that.data.index]; var userZone = that.data.userZoneList[that.data.index2]; var userlocation = that.data.userlocation; that.setData({ btnStatus: false, }) //所在城市 if (userZone == "" || userZone == null) { wx.showModal({ title: "", content: '请选择所在城市', showCancel: false, success: function (res) { if (res.confirm) { console.log('用户点击确定') } } }) that.setData({ btnStatus: true, }) return false; } //工程位置 if (userlocation == "" || userlocation == null) { wx.showModal({ title: "", content: '请选择工程位置', showCancel: false, success: function (res) { if (res.confirm) { console.log('用户点击确定') } } }) that.setData({ btnStatus: true, }) return false; } //房屋面积 if (acreage == "" || acreage == null) { wx.showModal({ title: "", content: '请选择您的房屋面积', showCancel: false, success: function (res) { if (res.confirm) { console.log('用户点击确定') } } }) that.setData({ btnStatus: true, }) return false; } //姓名 if (value.name == "" || value.name == null) { wx.showModal({ title: "", content: '姓名不能为空,请输入姓名', showCancel: false, success: function (res) { if (res.confirm) {
相关内容
- vue封装jquery修改自身及兄弟元素的方法_vue.js_
- JavaScript中rxjs与 Observable 两大类操作符解析_javascript技巧_
- React 中的列表渲染要加 key的原因分析_React_
- JS中的几种循环和跳出方式_javascript技巧_
- JS ES5创建常量详解_javascript技巧_
- 微信小程序实现日期格式化_javascript技巧_
- 微信小程序实现触底加载_javascript技巧_
- 微信小程序实现吸顶盒效果_javascript技巧_
- vue 动态添加el-input的实现逻辑_vue.js_
- 微信小程序scroll-view实现自定义滚动条_javascript技巧_
点击排行
本栏推荐
