<view class='a'>
<text> Hello {{name}}!</text>
<block wx:for='{{datas}}' wx:key='u'>
<button data-index='{{index}}' class='{{index==id?classname:""}}' data-m='{{t==index}}' bindtap="changeName"> {{item.data}} </button>
</block>
</view>
上面是wxml 三个btn,想实现点击添加classname(class='m'),下面是js部分,可以实现点击添加class='m'功能,但是当点击已添加class='m'按钮时,如何移除此时按钮的class?试了半天还没有想到办法
var datas = {
dataa: [{
data: 'click me1'
}, {
data: 'click me2'
}, {
data: 'click me3'
},
]
}
Page({
data: { name: 'lili', classname:'', datas: datas.dataa },
changeName: function (e) {
var x = e.currentTarget.dataset.index
console.log(e.detail)
this.setData({
name: 'MINA',
id: x,
classname:'m',
})
...
慕神8447489
相关分类