小程序表单提交详解-picker

                                      小程序表单提交详解

我这提交的是picker里的数据,如果传input的也可以参考此文。

1.wxml

<form bindsubmit='formSubmit'>

    <view class="section">

      <picker mode="date"  start="2014-09-01" end="2100-09-01" bindchange="bindDateChange">

         <view class="picker" name="customer_date">

            {{customer_date}}

         </view>

      </picker>

    </view>

    <button class='Button' formType="submit" >

       <text class='buttontext' >提交</text>

    </button>

  </form>

2.wxcss

.section{

  margin-top: 10px;

  margin-bottom: 40px;

}

.picker{

  padding: 15px;

  text-align: center;

  background-color: #FFFFFF;

}

.buttonview{

  text-align: center;

  margin: 0 auto;

}

.Button{

  width: 80%;

  background: linear-gradient(to right, #4D6FFB , #5CAFFF);

}

.buttontext{

color: #FFFFFF;

}

3.js

var transDate="";

Page({

  data:{ },

  bindDateChange: function (e) {

    console.log('picker发送选择改变,携带值为', e.detail.value);

    transDate = e.detail.value;   //将picker所选的值传给transDate

    this.setData({

       customer_date: e.detail.value  //执行setdata 函数,将picker所选的值在表单中显示出来,customer_date不是<view class="picker" name="customer_date">{{customer_date}}</view> 的name  ,是{{customer_date}}中的。

    })

  }, 

 

formSubmit:function(e){

    console.log('form发生了submit事件,携带数据为:', transDate );

    var data1={};

    data1.order_id= orderId;    //order_id为字段名 订单id

    data1.customer_date= transDate; // customer_date也是字段名

    console.log(data1.customer_date);  //控制台查看 ,也可不查看

    if (transDate==""){                //如果

      wx.showModal({

        title: '提示',

        content: '请输入转船日期',

      })

    }

    else {

      console.log(data1)

      wx.request({

        url: 'http://localhost/api/writeChangeShip', //  数据传到的地址

        data: data1,//传入的数据

        method: 'POST', 

        header: {// 设置请求的 header

          'content-type': 'application/x-www-form-urlencoded'   //这是传输方式为post的写法 ; 如果是get 则是'Content-Type': 'application/json'

        },

        success: function (res) {

          console.log(JSON.stringify(res.data))

          wx.showModal({      //提交成功 ,弹框

            content: '提交成功',

            success: function (res) {

              if (res.confirm) {   //如果点击弹框的确认则进行下面的操作

                // wx.navigateTo({

                //   url: '../orderlist/orderlist',

                // })

              }

            }

          })

        }

       

      })

    }


 

  },

})

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值