输入框,选择器

app.js

App({ onLaunch: function () { console.log('App Launch'); }, onShow: function () { console.log('App Show'); }, onHide: function () { console.log('App Hide'); } });

app.json

{ "pages": [ "pages/index/index" ], "window": { "navigationBarTitleText": "微信小程序示例" } }

index.js

Page({ data: { searchInput: '', swiperImages: [ '/images/image1.jpg', '/images/image2.jpg', '/images/image3.jpg' ], selectedTime: '12:00', selectedDate: '2023-01-01', customOptions: ['选项1', '选项2', '选项3'], selectedCustomOption: '选项1' }, bindSearchInput: function(e) { this.setData({ searchInput: e.detail.value }); console.log('搜索框输入:', this.data.searchInput); }, bindTimeChange: function(e) { this.setData({ selectedTime: e.detail.value }); console.log('选择的时间:', this.data.selectedTime); }, bindDateChange: function(e) { this.setData({ selectedDate: e.detail.value }); console.log('选择的日期:', this.data.selectedDate); }, bindPickerChange: function(e) { this.setData({ selectedCustomOption: this.data.customOptions[e.detail.value] }); console.log('选择的自定义选项:', this.data.selectedCustomOption); } });

index.wxml:

<view class="container"> <!-- 搜索框 --> <input type="text" bindinput="bindSearchInput" placeholder="请输入搜索内容" /> <!-- 轮播图 --> <swiper autoplay="true" indicator-dots="true" interval="5000" duration="500"> <block wx:for="{{swiperImages}}" wx:key="index"> <swiper-item> <image src="{{item}}" class="swiper-image" mode="aspectFill" /> </swiper-item> </block> </swiper> <!-- 时间选择器 --> <picker mode="time" value="{{selectedTime}}" bindchange="bindTimeChange"> <view class="picker"> 选择时间: {{selectedTime}} </view> </picker> <!-- 日期选择器 --> <picker mode="date" value="{{selectedDate}}" bindchange="bindDateChange"> <view class="picker"> 选择日期: {{selectedDate}} </view> </picker> <!-- 自定义选择器 --> <picker mode="selector" range="{{customOptions}}" bindchange="bindPickerChange"> <view class="picker"> 选择选项: {{selectedCustomOption}} </view> </picker> </view>

index.css:

.container { padding: 20px; } .swiper-image { width: 100%; height: 300px; } .picker { margin-top: 20px; padding: 10px; background-color: #f8f8f8; border-radius: 5px; }

效果图如图所示:

搜索框可以输入内容

时间选择器可以选择时间

日期选择器选择日期

还可以自己定义选项

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值