微信小程序 动态绑定事件并实现事件修改样式
实例代码
wxml
js
var pageObject = {
data: {
reportTypeList: reportTypeList,num: 0,toLeftNum: 0,itemWidth: 150
}
}
data: {
reportTypeList: reportTypeList,num: 0,toLeftNum: 0,itemWidth: 150
}
}
for (var i = 0; i < reportTypeList.length; i++) {
(function (item) {
pageObject['bind' + item.id] = function (e) {
var id = parseInt(e.currentTarget.dataset.typeid)
this.setData({
currentId: id
})
}
})(reportTypeList[i])
}
Page(pageObject)
wxss
.reportTypeScroll {
margin: 40px 0px 20px 0px;
white-space: nowrap;
display: flex;
}
margin: 40px 0px 20px 0px;
white-space: nowrap;
display: flex;
}
.clickSel {
color: red;
}
.removeSel {
color: black;
}
text {
height: 150rpx;
display: inline-block;
text-align: center;
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:https://www.f2er.com/weapp/39972.html