轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 微信小程序 查看主题

微信小程序点击button或view后选中其它反选

发布者: sunwei922 | 发布时间: 2018-7-15 05:37| 查看数: 3746| 评论数: 1|帖子模式

作者:蜗牛呆呆,来自原文地址

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

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

  1. <block wx:for="{{liuliangItems}}">
  2. <block wx:if="{{item.one2one == 1}}">
  3. <button class="{{item.changeColor?'selected2':'selected1'}}" type="default" id="{{item.price}}" data-id="{{item.name}}" data-one="{{item.one2one}}" data-orderid="{{item.id}}" data-number="1" bindtap="setPrice">{{item.name}}</button>
  4. </block>
  5. <block wx:else>
  6. <button class="{{item.changeColor?'selected':'normal'}}" type="default" id="{{item.price}}" data-id="{{item.name}}" data-one="{{item.one2one}}" data-orderid="{{item.id}}" data-number="1" bindtap="setPrice">{{item.name}}</button>
  7. </block>
  8. </block>
  1. wxss文件
  2. .normal{
  3. box-sizing: border-box;
  4. flex: 0 0 21%;
  5. margin: 5px 5px;
  6. height: 50px;
  7. color:#1aad19;
  8. border:1px solid #1aad19;
  9. background-color:transparent;
  10. }
  11. .selected{
  12. box-sizing: border-box;
  13. flex: 0 0 21%;
  14. margin: 5px 5px;
  15. height: 50px;
  16. background-color: #F75000;
  17. color: white;
  18. }
  19. .selected1{
  20. box-sizing: border-box;
  21. flex: 0 0 21%;
  22. margin: 5px 5px;
  23. height: 50px;
  24. background-color: transparent;
  25. border:1px solid #1aad19;
  26. color:#1aad19;
  27. background-image: url(https://wxcx.llzt.net/images/hot.png) ;
  28. background-position:31px 0px;
  29. background-repeat:no-repeat;
  30. background-size:62%;
  31. }
  32. .selected2{
  33. box-sizing: border-box;
  34. flex: 0 0 21%;
  35. margin: 5px 5px;
  36. height: 50px;
  37. background-color: #F75000;
  38. color: white;
  39. background-image: url(https://wxcx.llzt.net/images/hot.png);
  40. background-position:31px 0px;
  41. background-repeat:no-repeat;
  42. background-size:62%;
  43. }

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

  1. for (var i = 0; i < this.data.liuliangItems.length; i++) {
  2. if (e.target.dataset.orderid == this.data.liuliangItems[i].id) {
  3. txtArray1[i] = {
  4. id: this.data.liuliangItems[i].id, changeColor: true,
  5. price: this.data.liuliangItems[i].price, name: this.data.liuliangItems[i].name,
  6. one2one: this.data.liuliangItems[i].one2one
  7. }
  8. } else {
  9. txtArray1[i] = {
  10. id: this.data.liuliangItems[i].id, changeColor: false,
  11. price: this.data.liuliangItems[i].price, name: this.data.liuliangItems[i].name,
  12. one2one: this.data.liuliangItems[i].one2one
  13. }
  14. }
  15. }

最新评论

wsjsww 发表于 2022-7-6 12:01
源代码怎么下载歌曲

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表