微信小程序时间控件picker view使用详解
网络编程 2021-07-04 15:50www.168986.cn编程入门
这篇文章主要介绍了微信小程序时间控件picker view的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了微信小程序时间控件的具体实现代码,供大家参考,具体内容如下
在原来基础上改了点,由于项目需要按照功能需求自己在原有的组件上改写的选择日期时间插件,但后来这个功能取消,所以整理下写下来
wxml:
<view class="time_screens"> <view style="text-align:center;color:#45BCE8">{{year}}-{{month}}-{{day}} {{hour}}:{{minute}}<label style="float:right;margin-right:10px;">确定</label></view> <view style="border-:1px solid #45BCE8;height:25px;font-size:14px;"> <view class="time-title">年</view> <view class="time-title">月</view> <view class="time-title">日</view> <view class="time-title">时</view> <view class="time-title">分</view> </view> <picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" value="{{value}}" bindchange="bindChange"> <picker-view-column class="picker-text"> <view wx:for="{{years}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{months}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{days}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{hours}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{minutes}}" style="line-height: 50px">{{item}}</view> </picker-view-column> </picker-view> </view>
wxss:
.time-title{ float:left;width:20%;text-align:center;color:#45BCE8 } .picker-text{ text-align:center; } /mask/ .time_screens { width: 100%; position: fixed; bottom: 0; left: 0; z-index: 1000; opacity: 0.5; overflow: hidden; }
js
const date = new Date() const years = [] const months = [] const days = [] const hours = [] const minutes = [] var thisMon = date.getMonth(); var thisDay = date.getDate(); for (let i = 2017; i <= date.getFullYear()+1; i++) { years.push(i) } for (let i = date.getMonth(); i <= 11; i++) { var k = i; if (0 <= i && i < 9) { k = "0" + (i+1); }else{ k = (i + 1); } months.push(k) } if (0 <= thisMon && thisMon<9){ thisMon = "0" + (thisMon + 1); }else{ thisMon = (thisMon + 1); } if (0 <= thisDay && thisDay<10){ thisDay ="0"+thisDay; } var totalDay = mGetDate(date.getFullYear(), thisMon); for (let i = 1; i <= 31; i++) { var k = i; if (0 <= i && i < 10) { k = "0" + i } days.push(k) } for (let i = 0; i <= 23; i++) { var k=i; if(0<=i&&i<10){ k="0"+i } hours.push(k) } for (let i = 0; i <= 59; i++) { var k = i; if (0 <= i && i < 10) { k = "0" + i } minutes.push(k) } function mGetDate(year, month) { var d = new Date(year, month, 0); return d.getDate(); } Page({ data: { years: years, year: date.getFullYear(), months: months, month: thisMon, days: days, day: thisDay, value: [1,thisMon-1,thisDay-1,0,0], hours: hours, hour: "00", minutes: minutes, minute: "00", }, bindChange: function (e) { const val = e.detail.value this.setData({ year: this.data.years[val[0]], month: this.data.months[val[1]], day: this.data.days[val[2]], hour: this.data.hours[val[3]], minute: this.data.minutes[val[4]], }) var totalDay = mGetDate(this.data.year, this.data.month); var changeDate=[]; for (let i = 1; i <= totalDay; i++) { var k = i; if (0 <= i && i < 10) { k = "0" + i } changeDate.push(k) } this.setData({ days: changeDate }) }, })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程