小程序在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',
})
})