微信小程序中的日期选择插件如何用
发表于:2025-02-06 作者:千家信息网编辑
千家信息网最后更新 2025年02月06日,本篇内容主要讲解"微信小程序中的日期选择插件如何用",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"微信小程序中的日期选择插件如何用"吧!效果图:wxml
千家信息网最后更新 2025年02月06日微信小程序中的日期选择插件如何用
本篇内容主要讲解"微信小程序中的日期选择插件如何用",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"微信小程序中的日期选择插件如何用"吧!
效果图:
wxml
《 {{cur_year || "--"}} 年 {{cur_month || "--"}} 月 》 {{item}} {{item}} 点击日期选择
js
//index.js//获取应用实例Page({ data: { hasEmptyGrid: false, cur_year: '', cur_month: '', }, onLoad(options) { this.setNowDate(); }, dateSelectAction: function (e) { var cur_day = e.currentTarget.dataset.idx; this.setData({ todayIndex: cur_day }) console.log(`点击的日期:${this.data.cur_year}年${this.data.cur_month}月${cur_day + 1}日`); }, setNowDate: function () { const date = new Date(); const cur_year = date.getFullYear(); const cur_month = date.getMonth() + 1; const todayIndex = date.getDate() - 1; console.log(`日期:${todayIndex}`) const weeks_ch = ['日', '一', '二', '三', '四', '五', '六']; this.calculateEmptyGrids(cur_year, cur_month); this.calculateDays(cur_year, cur_month); this.setData({ cur_year: cur_year, cur_month: cur_month, weeks_ch, todayIndex, }) }, getThisMonthDays(year, month) { return new Date(year, month, 0).getDate(); }, getFirstDayOfWeek(year, month) { return new Date(Date.UTC(year, month - 1, 1)).getDay(); }, calculateEmptyGrids(year, month) { const firstDayOfWeek = this.getFirstDayOfWeek(year, month); let empytGrids = []; if (firstDayOfWeek > 0) { for (let i = 0; i < firstDayOfWeek; i++) { empytGrids.push(i); } this.setData({ hasEmptyGrid: true, empytGrids }); } else { this.setData({ hasEmptyGrid: false, empytGrids: [] }); } }, calculateDays(year, month) { let days = []; const thisMonthDays = this.getThisMonthDays(year, month); for (let i = 1; i <= thisMonthDays; i++) { days.push(i); } this.setData({ days }); }, handleCalendar(e) { const handle = e.currentTarget.dataset.handle; const cur_year = this.data.cur_year; const cur_month = this.data.cur_month; if (handle === 'prev') { let newMonth = cur_month - 1; let newYear = cur_year; if (newMonth < 1) { newYear = cur_year - 1; newMonth = 12; } this.calculateDays(newYear, newMonth); this.calculateEmptyGrids(newYear, newMonth); this.setData({ cur_year: newYear, cur_month: newMonth }) } else { let newMonth = cur_month + 1; let newYear = cur_year; if (newMonth > 12) { newYear = cur_year + 1; newMonth = 1; } this.calculateDays(newYear, newMonth); this.calculateEmptyGrids(newYear, newMonth); this.setData({ cur_year: newYear, cur_month: newMonth }) } }})
到此,相信大家对"微信小程序中的日期选择插件如何用"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
日期
选择
插件
程序
内容
学习
实用
更深
兴趣
实例
实用性
实际
操作简单
效果
效果图
方法
更多
朋友
网站
频道
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
拦截服务器ssl还安全么
靠谱的财务管理软件开发定制公司
数据库地址如何恢复
国企是做软件开发的
体系国家网络安全
云服务器国外
开源自定义数据库
网络安全法制日宣传周
郧西智能软件开发专业服务
服务器文件系统使用率
饥荒有哪些大型服务器
财险公司网络安全保障工作
软件开发工作群
怎么在电脑上设置存储服务器
软件开发者的职称
泰拉瑞亚1.4开荒服务器ip
简历上写软件开发的小项目
莱阳安卓软件开发哪家好
常见的软件开发模型包括
成都软件开发教程
ssm关闭数据库连接
数据库中的第三范式
网吧怎么组建双服务器
数据库怎么防止注入
湛江应用软件开发费用是多少
建筑企业数据库演讲
网络安全法个人书面发言记录
金太阳考试服务器
全自动分拣配送软件开发
绝地求生架设服务器