小程序筆記四:表單提交form


 

index.wxml代碼

<form bindsubmit="formSubmit" bindreset="formReset">
    <view class='box address-mode'>
        <view class='item clearfix'>
            <view class="float-li t1">收貨人:</view>
            <view class="float-li t2"><input name="name" maxlength="6" placeholder="請輸入收貨人" /></view>
        </view>
        <view class='item clearfix'>
            <view class="float-li t1">手機:</view>
            <view class="float-li t2"><input name="mobile"  type="number" maxlength="11" placeholder="請輸入手機" /></view>
        </view>
        
        <view class='item clearfix' style='height: 50rpx;'>
            <view class="float-li t1">省市地區:</view>
            <view class="float-li t2" bindtap='pikerScenes'>{{region[0]['regname']}},{{region[1]['regname']}},{{region[2]['regname']}}</view>
        </view>
        
        <view class='item clearfix' style='height: 100rpx;'>
            <view class="float-li t1">詳細地址:</view>
            <view class="float-li t2"><textarea name="address"  maxlength="-1" style='height: 80rpx'/></view>
            
        </view>
    </view>
    <view class="blank"></view>
    <!--按鈕-->
    <view class="address-button"><button class='btn' formType="submit" bindtap='clickAdr'>保存地址</button></view>
    </form>

  

index.js代碼

 1 formSubmit: function (e) {
 2     var that = this
 3     var regionInfo = that.data.regionInfo
 4     var token = wx.getStorageSync('token')
 5     var name = e.detail.value.name
 6     var mobile = e.detail.value.mobile
 7     var address = e.detail.value.address
 8     //var province = 6   // 廣東
 9     //var city = 77  // 深圳
10     //var district =  708   // 西鄉
11     var province = regionInfo[0]['regid']   //
12     var city = regionInfo[1]['regid']  //
13     var district = regionInfo[2]['regid']   //
14 
15 
16     wx.request({
17       url: app.api.saveAddress,
18       data: { consignee: name, mobile: mobile, address: address, token: token.token, email: '', province: province, city: city, district: district},
19       success:function(e){
20         // 重新刷新地址列表
21         that.requestAddressList()
22 
23         if(e.data.code ==0){
24           var ttl='提交成功'
25         }else{
26           var ttl='提交失敗'
27         }
28 
29         wx.showModal({
30           content: ttl,
31           showCancel: false,
32           success: function (res) {
33             if (res.confirm) {
34               console.log('用戶點擊確定')
35             } else if (res.cancel) {
36               console.log('用戶點擊取消')
37             }
38           }
39         })
40       }
41     })
42 
43   },

 

參考手冊:

https://mp.weixin.qq.com/debug/wxadoc/dev/component/form.html

https://mp.weixin.qq.com/debug/wxadoc/dev/component/input.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM