微信小程序 实现点击添加移除class

花开花谢,人来又走,夕阳西下,人去楼空,早已物是人非矣。也许,这就是结局,可我不曾想过结局是这样;也许,这就是人生的意义,可我不曾想竟是生离死别。

微信小程序点击添加移除class类实现动态变化class


wxml:

<view class="location_bottom" hidden="" > 
   <view class="{{_num == 1?'add_citying':'add_city'}}" data-num = "1" bindtap="clickNum">北京</view> 
   <view class="{{_num == 2?'add_citying':'add_city'}}" data-num = "2" bindtap="clickNum">上海</view> 
 </view> 

wxss:

.location_bottom{height: 140rpx;line-height: 140rpx;color: #d91f16;font-size:
 28rpx;border-top: 2rpx #ebebeb solid; border-bottom: 2rpx #ebebeb solid; padding: 0 20rpx; align-items: center;display: -webkit-flex;} 
.add_city{width: 228rpx;height: 60rpx;line-height: 60rpx; text-align: center; border: 2rpx 
solid #ebebeb; color: #000000;margin-right: 20rpx; } 
.add_citying{width: 228rpx;height: 60rpx;line-height: 60rpx; text-align: center;
 border: 2rpx solid #09bb07; color: #09bb07;margin-right: 20rpx;} 

js:

Page({ 
 data: { 
  _num: 0,   
 }, 
 clickNum: function (e) { 
  console.log(e.target.dataset.num) 
  this.setData({ 
   _num: e.target.dataset.num 
  }) 
 }, 
 onLoad: function (options) { 
 
 } 
 
  
}) 

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

到此这篇关于微信小程序 实现点击添加移除class就介绍到这了。积极思考造成积极人生,消极思考造成消极人生。更多相关微信小程序 实现点击添加移除class内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
微信小程序如何访问公众号文章

微信小程序实现类似微信点击语音播放效果

微信小程序wx.request拦截器使用详解

微信小程序在ios下Echarts图表不能滑动的问题解决

小程序中canvas的drawImage方法参数使用详解