小程序国家、时间、日期选择器(转)
js代码:
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
date: '2016-11-08',
time: '12:00',
array: ['中国', '巴西', '日本', '美国'],
index: 0,
},
onLoad: function () {
},
// 点击时间组件确定事件
bindTimeChange: function (e) {
this.setData({
time: e.detail.value
})
},
// 点击日期组件确定事件
bindDateChange: function (e) {
this.setData({
date: e.detail.value
})
},
// 点击国家组件确定事件
bindPickerChange: function (e) {
this.setData({
index: e.detail.value
})
}
})
wxml代码:
<view class="section" style="background:#787878;margin:20rpx;padding:20rpx">
<picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
<view class="picker">
国家:{{array[index]}}
</view>
</picker>
</view>
<view class="section" style="background:#787878;margin:20rpx;padding:20rpx">
<picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
<view class="picker">
时间: {{time}}
</view>
</picker>
</view>
<view class="section" style="background:#787878;margin:20rpx;padding:20rpx">
<picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
<view class="picker">
日期: {{date}}
</view>
</picker>
</view>