微信小程序—时间选择器:时分秒

本文介绍了在微信小程序开发中遇到的自带时间选择器不包含秒数的问题,作者分享了如何根据已有资源,自定义一个包含时分秒的时间选择器。通过在wxml文件中定义输入框,并在js页面中编写相关逻辑,实现了完整的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在做小程序中,其中自带的时间选择器没有秒数,所以上网查了很多方法,但是跟我的想法不同,所以根据其他人的,自己写了我自己的方法。

wxml文件中定义输入框

< view class = "section">
< picker mode = "multiSelector" value = "{ {startTime}}" bindchange = "startTimeChange" bindcolumnchange = "startTimeColumn" range = "{ {startTimeArray}}">
< view class = "picker">
< view class = "top grid">
< label class = "title col-0"> 开始时间 </ label >
< input class = "input_base input_h30 col-1" name = "startTime" value = "{ {startTimeArray[0][startTime[0]]}}:{ {startTimeArray[1][startTime[1]]}}:{ {startTimeArray[2][startTime[2]]}}"></ input >
</ view >
</ view >
好的,关于微信小程序时间选择弹窗时分秒的问题,你可以通过以下代码来实现: 1. 在 WXML 文件中添加以下代码: ``` <view class="container"> <view class="btn" bindtap="showTimePicker">择时间</view> </view> <view class="picker-container" wx:if="{{showPicker}}"> <view class="picker-mask" bindtap="hidePicker"></view> <view class="picker"> <picker mode="time" value="{{time}}" bindchange="bindTimeChange"> <view class="time-picker"> {{time}} </view> </picker> </view> </view> ``` 2. 在相关的 WXSS 文件中添加以下代码: ``` .container { display: flex; justify-content: center; align-items: center; height: 100vh; } .btn { background-color: #007aff; color: #fff; padding: 10px 20px; border-radius: 5px; } .picker-container { position: fixed; top: 0; left: 0; z-index: 999; width: 100%; height: 100%; } .picker-mask { background-color: rgba(0, 0, 0, 0.5); width: 100%; height: 100%; } .picker { position: absolute; bottom: 0; left: 0; right: 0; background-color: #fff; padding: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; } .time-picker { display: flex; justify-content: center; align-items: center; font-size: 20px; font-weight: bold; margin: 20px 0; } ``` 3. 在相关的 JS 文件中添加以下代码: ``` Page({ data: { showPicker: false, time: '12:00', }, showTimePicker() { this.setData({ showPicker: true, }); }, hidePicker() { this.setData({ showPicker: false, }); }, bindTimeChange(e) { this.setData({ time: e.detail.value, }); }, }); ``` 这样就可以实现微信小程序时间选择弹窗时分秒了,具体效果可以通过微信开发者工具进行查看。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值