1. <form bindsubmit="formSubmit" bindreset="formReset">
    2. <view class="group">
    3. <view class="title">用户名:</view>
    4. <view class="cont">
    5. <input type="text" name="username" placeholder="请输入用户名"/>
    6. </view>
    7. <view class="clear"></view>
    8. </view>
    9. <view class="group">
    10. <view class="title">性别:</view>
    11. <view class="cont">
    12. <radio-group name="gender">
    13. <label><radio value="1"/></label>
    14. <label><radio value="0"/></label>
    15. </radio-group>
    16. </view>
    17. <view class="clear"></view>
    18. </view>
    19. <view class="group">
    20. <view class="title">food:</view>
    21. <view class="cont">
    22. <checkbox-group name="hobby">
    23. <label><checkbox value="0"/>蛋糕</label>
    24. <label><checkbox value="1"/>牛排</label>
    25. <label><checkbox value="1"/>排骨头</label>
    26. </checkbox-group>
    27. </view>
    28. <view class="clear"></view>
    29. </view>
    30. <view class="group">
    31. <view class="title">同意:</view>
    32. <view class="cont">
    33. <switch name="isagree"/>
    34. </view>
    35. <view class="clear"></view>
    36. </view>
    37. <view class="group">
    38. <button form-type="submit">提交表单</button>
    39. <button form-type="reset">清空表单</button>
    40. </view>
    41. </form>
    1. .clear{
    2. clear: both;
    3. }
    4. .title{
    5. float: left;
    6. width: 100px;
    7. text-align: right;
    8. }
    9. .cont{
    10. float: left;
    11. }
    12. input{
    13. border:1px solid gainsboro;
    14. }
    15. .group{
    16. margin-top:20px;
    17. }
    1. // 提交表单函数
    2. formSubmit:function(e){
    3. console.log(e);
    4. console.log("表单已经提交!");
    5. console.log("用户名:"+e.detail.value.username);
    6. console.log("性别:" + (e.detail.value.gender==1?"男":"女"));
    7. },
    8. // 清空表单函数
    9. formReset:function(e){
    10. console.log("表单已经清空!");
    11. },

    效果图:
    表单提交和清空 - 图1

    注意:formSubmit为表单提交后执行的函数,e.detail.value中是表单提交上来的数据,这里要注意,存放数据的标签一定要有name属性值才能获取数据