<form class="" bindsubmit="getData"> <view > <input class="" name="iphone" type="text" placeholder="手机号"></input> </view> <view > <input class="" name="code" type="text" placeholder="验证码" ></input> <input class="" name="time" type="buttom" value="{{time}}s"></input> </view > <view > <button bind:tap="sendFun" type="primary">发送消息</button> </view > <view > <button form-type="submit">验证用户</button> </view > </form>
// pages/form/form.js Page({ /** * 页面的初始数据 */ data: { timer: null, time:3 }, onLoad: function (options) { }, sendFun(e){ let time = this.data.time; this.data.timer = setInterval(() => { time--; if(time == 0) clearInterval(this.data.timer);//如果等于0 不继续减 this.setData({ time }) }, 1000);//一秒减一次 }, getData(e){ console.log(e);//获取的data值 }, })
bindsubmit 获取的表单数据
form-type="submit" button的标签 必须有才可提交