废话不多说直接上代码:
index.html 页面
<!--小程序表单--> <view class="container"> <form bindsubmit="formSubmit" bindreset="formReset"> <view style="margin-bottom:20rpx"> <input name="input" placeholder="输入" /> </view> <view style="margin-bottom:20rpx"> <checkbox-group name="checkbox"> <checkbox value="cb" checked="true"/> checkbox </checkbox-group> </view> <view style="margin-bottom:20rpx"> <switch name="switch"/> </view> <view style="margin-bottom:20rpx"> <radio-group name="radio"> <label><radio value="radio1"/>radio1</label> <label><radio value="radio2"/>radio2</label> </radio-group> </view> <view style="margin-bottom:20rpx"> <slider value="50" name="slider" show-value ></slider> </view> <view> <button type="primary" formType="submit">提交</button> <button formType="reset">重置</button> </view> </form> </view>
index.js页面
// index.js // 获取应用实例 const app = getApp() Page({ data: { }, formSubmit: function(e) { console.log(e) }, formReset: function (e) { }, onLoad() { } })
这时候我们点击提交的时候 在 e 对象里面就能拿到from 里面的值了
记住 不要忘了定义name 属性
嗨,这是一条评论。
要开始审核、编辑及删除评论,请访问仪表盘的“评论”页面。
评论者头像来自Gravatar。