How to develop a date picker for a WeChat applet
Everyone who has used the date picker in the WeChat applet will find that there is a big problem.
It is in February Sometimes there will be 31 days, and various situations such as leap year judgment are not carried out. After reading the source code provided by
, I made some modifications and tested it to fix the bug mentioned above!
Source code below:
----------------------- I am the dividing line--------------------------
<!---js---》 const date = new Date();//获取系统日期 const years = [] const months = [] const days = [] const bigMonth = [1,3,5,7,8,10,12] //将日期分开写入对应数组 //年 for (let i =1990; i <= date.getFullYear(); i++) { years.push(i); } //月 for (let i =1; i <= 12; i++) { months.push(i); } //日 for (let i =1; i <= 31; i++) { days.push(i); } Page({ /** * 页面的初始数据 */ data: { years: years, year: date.getFullYear(), months: months, month: 2, days: days, day: 2, value: [9999, 1, 1], }, showToask: function() { wx.showToast({ title: '成功', icon: 'success', duration: 2000 }) }, //判断元素是否在一个数组 contains: function(arr, obj) { var i = arr.length; while(i--) { if (arr[i] === obj) { return true; } } return false; }, setDays: function (day) { const temp = []; for(let i =1; i<=day; i++) { temp.push(i) } this.setData({ days: temp, }) }, showLoading: function () { wx.showLoading({ title: '加载中...', }), setTimeout(function () { wx.hideLoading() },2000) }, //选择滚动器改变触发事件 bindChange: function (e) { const val = e.detail.value; //判断月的天数 const setYear = this.data.years[val[0]]; const setMonth = this.data.months[val[1]]; const setDay = this.data.days[val[2]] // console.log(setYear + '年' + setMonth + '月' + setDay + '日'); //闰年 if (setMonth === 2) { if (setYear % 4 === 0 && setYear % 100 !== 0) { // console.log('闰年') this.setDays(28); } else { // console.log('非闰年') this.setDays(29); } }else { //大月 if (this.contains(bigMonth, setMonth)){ this.setDays(31) }else { this.setDays(30) } } this.setData({ year: setYear, month: setMonth, day: setDay }) } })
------- ------------------I am the dividing line--------------------
<!---wxml---> 与官方文档是一样的! <view style='text-align:center;margin-top:30px;'>{{year}}年{{month}}月{{day}}日</view> <picker-viewindicator-style="height:50px;"style='width:100%;height:300px;text-align:center'value="{{value}}"bindchange="bindChange"> <picker-view-column> <view wx:for="{{years}}" wx:key="year" style='line=height:50px;'> {{item}}年 </view> </picker-view-column> <picker-view-column> <view wx:for="{{months}}" wx:key="month"> {{item}}月 </view> </picker-view-column> <picker-view-column> <view wx:for="{{days}}" wx:key="day"> {{item}}日 </view> </picker-view-column> </picker-view> </view>
The above is the detailed content of How to develop a date picker for a WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

1. First open the mobile web browser, search for the Weibo web version, and click the avatar button in the upper left corner after entering. 2. Then click Settings in the upper right corner. 3. Click the version switching option in settings. 4. Then select the color version option in the version switch. 5. Click Search to enter the search page. 6. After entering the keywords, click Find People. 7. When the search completion interface appears, click Filter. 8. Finally, enter the specific date in the release time column and click Filter.

C++ is a widely used programming language that is very convenient and practical in writing countdown programs. Countdown program is a common application that can provide us with very precise time calculation and countdown functions. This article will introduce how to use C++ to write a simple countdown program. The key to implementing a countdown program is to use a timer to calculate the passage of time. In C++, we can use the functions in the time.h header file to implement the timer function. The following is the code for a simple countdown program

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

Do you frequently visit the same website at about the same time every day? This can lead to spending a lot of time with multiple browser tabs open and cluttering the browser while performing daily tasks. Well, how about opening it without having to launch the browser manually? It's very simple and doesn't require you to download any third-party apps, as shown below. How do I set up Task Scheduler to open a website? Press the key, type Task Scheduler in the search box, and then click Open. Windows On the right sidebar, click on the Create Basic Task option. In the Name field, enter the name of the website you want to open and click Next. Next, under Triggers, click Time Frequency and click Next. Select how long you want the event to repeat and click Next. Select enable

1. Let me first talk about the method I used at the beginning, maybe everyone is using it too. First, open [View]——]Remarks Template[. 2. A place where you can actually see the date after opening it. 3. Select it first and delete it. 4. After deleting, click [Close Master View]. 5. Open the print preview again and find that the date is still there. 6. In fact, this date was not deleted here. It should be in the [Handout Master]. Look at the picture below. 7. Delete the date after you find it. 8. Now when you open the preview and take a look, the date is no longer there. Note: In fact, this method is also very easy to remember, because the printed handouts are handouts, so you should look for the [Handout Master].

Are you getting "Unable to allow access to camera and microphone" when trying to use the app? Typically, you grant camera and microphone permissions to specific people on a need-to-provide basis. However, if you deny permission, the camera and microphone will not work and will display this error message instead. Solving this problem is very basic and you can do it in a minute or two. Fix 1 – Provide Camera, Microphone Permissions You can provide the necessary camera and microphone permissions directly in settings. Step 1 – Go to the Settings tab. Step 2 – Open the Privacy & Security panel. Step 3 – Turn on the “Camera” permission there. Step 4 – Inside, you will find a list of apps that have requested permission for your phone’s camera. Step 5 – Open the “Camera” of the specified app

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l
