微信小程序 点击控件后选中其它反选实例详解

微信小程序 点击控件后选中其它反选实例详解

前言:

如果需要实现进来进行给按钮加上买一送一的样式,或者单击就选中单个按钮,只能靠css结合js进行控制了,小程序暂时没有这样的控件。

实现效果图:

微信小程序进来的时候自动进行按钮样式的初始化,这个需要一个字段做判断,加上正则表达式wxml文件

rush:js;">

wxss文件

rush:xml;"> .normal{ Box-sizing: border-Box; flex: 0 0 21%; margin: 5px 5px; height: 50px; color:#1aad19; border:1px solid #1aad19; background-color:transparent; } .selected{ Box-sizing: border-Box; flex: 0 0 21%; margin: 5px 5px; height: 50px; background-color: #F75000; color: white; } .selected1{ Box-sizing: border-Box; flex: 0 0 21%; margin: 5px 5px; height: 50px; background-color: transparent; border:1px solid #1aad19; color:#1aad19; background-image: url(https://wxcx.llzt.net/images/hot.png) ; background-position:31px 0px; background-repeat:no-repeat; background-size:62%; } .selected2{ Box-sizing: border-Box; flex: 0 0 21%; margin: 5px 5px; height: 50px; background-color: #F75000; color: white; background-image: url(https://wxcx.llzt.net/images/hot.png); background-position:31px 0px; background-repeat:no-repeat; background-size:62%; }

现在的方法把集合进行循环,然后获取当前点击的这个按钮进行比较,然后进行样式的修改

rush:xml;"> for (var i = 0; i < this.data.liuliangItems.length; i++) { if (e.target.dataset.orderid == this.data.liuliangItems[i].id) { txtArray1[i] = { id: this.data.liuliangItems[i].id,changeColor: true,price: this.data.liuliangItems[i].price,name: this.data.liuliangItems[i].name,one2one: this.data.liuliangItems[i].one2one } } else { txtArray1[i] = { id: this.data.liuliangItems[i].id,changeColor: false,one2one: this.data.liuliangItems[i].one2one } } }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

相关文章

开发微信小程序的用户授权登录功能
小程序开发页面如何实现跳转?
浅谈小程序开发中蓝牙连接错误分析及解决方法
什么是小程序?它有哪些功能?
如何配置小程序开发项目结构?(教程)
怎么把自己的店加入小程序