Home >WeChat Applet >Mini Program Development >WeChat applet picker date and time picker

WeChat applet picker date and time picker

高洛峰
高洛峰Original
2017-02-18 13:06:483413browse

The following is an introduction to the small picker, which is divided into three styles:

  • The default one can define the data by yourself

  • ##mode="time" It is a time picker

  • mode="date"It is a date picker

Like the others, let’s take a look at picker.wxml

<view class="page">
 <view class="page__hd">
 <text class="page__title">picker</text>
 <text class="page__desc">选择器</text>
 </view>
 <view class="page__bd">
 <view class="section">
  <view class="section__title">地区选择器</view>
  <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
  <view class="picker">
   当前选择:{{array[index]}}
  </view>
  </picker>
 </view>
 <view class="section">
  <view class="section__title">时间选择器</view>
  <picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
  <view class="picker">
   当前选择: {{time}}
  </view>
  </picker>
 </view>

 <view class="section">
  <view class="section__title">日期选择器</view>
  <picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
  <view class="picker">
   当前选择: {{date}}
  </view>
  </picker>
 </view>
 </view>
</view>

picker.wxss

page {
 background-color: #fbf9fe;
 height: 100%;
}
.page__hd{
 padding: 50rpx 50rpx 100rpx 50rpx;
 text-align: center;
}
.page__title{
 display: inline-block;
 padding: 20rpx 40rpx;
 font-size: 32rpx;
 color: #AAAAAA;
 border-bottom: 1px solid #CCCCCC;
}
.page__desc{
 display: none;
 margin-top: 20rpx;
 font-size: 26rpx;
 color: #BBBBBB;
}
.section{
 margin-bottom: 80rpx;
}
.section__title{
 margin-bottom: 16rpx;
 padding-left: 30rpx;
 padding-right: 30rpx;
}
.picker{
 padding: 26rpx;
 background-color: #FFFFFF;
}

picker.js

Page({
 data: {
 array: [&#39;中国&#39;, &#39;美国&#39;, &#39;巴西&#39;, &#39;日本&#39;],
 index: 0,
 date: &#39;2016-09-01&#39;,
 time: &#39;12:01&#39;
 },
 bindPickerChange: function(e) {
 console.log(&#39;picker发送选择改变,携带值为&#39;, e.detail.value)
 this.setData({
  index: e.detail.value
 })
 },
 bindDateChange: function(e) {
 this.setData({
  date: e.detail.value
 })
 },
 bindTimeChange: function(e) {
 this.setData({
  time: e.detail.value
 })
 }
})

demo address: WeAppDemo_jb51.rar


The following are three types of page display


WeChat applet picker date and time picker

Style diagram:

1. By default you can define the data

WeChat applet picker date and time picker

2. mode="time" is the time selector

WeChat applet picker date and time picker

3. mode="date" is the date picker

WeChat applet picker date and time picker

The above is the entire content of this article, I hope it will be helpful to everyone's study , I also hope that everyone will support the PHP Chinese website.

For more articles related to the picker date and time selector of the WeChat applet, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn