温馨提示×

小程序怎么在js中获取页面的值

小新
135
2020-12-10 09:13:03
栏目: 云计算

小程序怎么在js中获取页面的值

小程序在js中获取页面的值案例:

在对应的wxml页面中添加以下代码:

<form bindsubmit='formsubmit'>

<view class='Type'>

  <van-cell title="类型" is-link>

  <picker name="vtype" bindchange="bindTypeChange" value="{{TypeIndex}}" range="{{Types}}">

    <view class="selectIndex1">{{Types[TypeIndex]}}</view>

  </picker>

  </van-cell>

</view>

<!-- button按钮 -->

<button class="issue-btn" type="default" form-type='submit'>按钮</button>

</form>

在对应的js页面中添加以下代码:

Page({

data: {

    Types: ["宣传片", "广告片", "纪录片", "短视频"],

    TypeIndex: 0,

},

//获取下标

bindTypeChange: function (e) {

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

    this.setData({

      TypeIndex: e.detail.value

    })

  },

//表单提交按钮

formsubmit: function (e){

var type = this.data.Types[this.data.TypeIndex];

//打印出来,看是否获取成功了

console.log(' type :', type);

}

wx.redirectTo({

      url: '/pages/payOrder/Contract/contract',

    })

})

0