您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
微信小程序 动态绑定事件并实现事件修改样式
实例代码
wxml
<scroll-view class="reportTypeScroll" scroll-x="true" scroll-left="{{toLeftNum}}"> <block wx:for-items="{{reportTypeList}}" wx:key="{{index}}"> <text type="primary" bindtap="bind{{item.id}}" data-typeid="{{item.id}}" class="{{currentId==item.id?'clickSel':'removeSel'}}">{{item.name}}</text> </block> </scroll-view>
js
var reportTypeList = [ { name: "日报1", id: "1" }, { name: "目录2", id: "2" }, { name: "季报3", id: "3" }, { name: "月报4", id: "4" }, { name: "日报5", id: "5" }, { name: "目录6", id: "6" }, { name: "季报7", id: "7" }, { name: "月报8", id: "8" }, { name: "日报9", id: "9" }, { name: "目录10", id: "10" }, { name: "季报11", id: "11" }, { name: "月报12", id: "12" }] var pageObject = { 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
/**index.wxss**/ .reportTypeScroll { 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; }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。