### [微信小程序实现下拉框(附代码)](https://www.prosaas.cn/article/17189) **Published:** 2018-08-07T01:53:44 **Author:** 5201314 **Excerpt:** 微信小程序里没有和HTML里的下拉框一样的组件,想要相同的效果只能自己写一个,先看效果 下面来看一下代码:首先… 微信小程序里没有和HTML里的下拉框一样的组件,想要相同的效果只能自己写一个,先看效果 ![](https://img.php.cn//upload/image/663/108/582/1533606677905742.gif)  下面来看一下代码: 首先WXML {{selectData\[index\]}} {{item}} 然后WXSS(如果不想要动画,删掉wxss里的transition:transform 0.3s;和transition: height 0.3s;即可) page{ background: #f3f7f7; } .select\_box{ background: #fff; width: 80%; margin: 30rpx auto; position: relative; } .select{ box-sizing: border-box; width: 100%; height: 70rpx; border:1px solid #efefef; border-radius: 8rpx; display: flex; align-items: center; padding: 0 20rpx; } .select\_text{ font-size: 30rpx; flex: 1; } .select\_img{ width: 40rpx; height: 40rpx; display: block; transition:transform 0.3s; } .select\_img\_rotate{ transform:rotate(180deg); } .option\_box{ position: absolute; top: 70rpx; width: 100%; border:1px solid #efefef; box-sizing: border-box; height: 0; overflow-y: auto; border-top: 0; background: #fff; transition: height 0.3s; } .option{ display: block; line-height: 40rpx; font-size: 30rpx; border-bottom: 1px solid #efefef; padding: 10rpx; } 这里是JS Page({ data: { show:false,//控制下拉列表的显示隐藏,false隐藏、true显示 selectData:\['1','2','3','4','5','6'\],//下拉列表的数据 index:0//选择的下拉列表下标 }, // 点击下拉显示框 selectTap(){ this.setData({ show: !this.data.show }); }, // 点击下拉列表 optionTap(e){ let Index=e.currentTarget.dataset.index;//获取点击的下拉列表的下标 this.setData({ index:Index, show:!this.data.show }); }, onLoad: function (options) { } }) 相关推荐: 微信小程序实现分页下拉加载的实例代码 微信小程序中的下拉刷新和上拉加载的实现方法详解 以上就是微信小程序实现下拉框(附代码)的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** html, JS, transform, transition, 微信小程序 **Categories:** 后端开发 ---