wxml
<view class="list top float">
<view>简单的复选框</view>
<view>
<view wx:for="{{checkArr}}" wx:key="id" catchtap="checkArr" data-id="{{index}}"
class="{{item.check == true ? 'red':''}}">
{{item.content}}
</view>
</view>
</view>
css
.red{
color: red;
}
Js
checkArr: [{id: 1,check: '',content: "复选1"},
{id: 2,check: '',content: "复选2"},
{id: 3,check: '',content: "复选3"},
{id: 4,check: '',content: "复选4"},
{id: 5,check: '',content: "复选5"},
{id: 6,check: '',content: "复选6"}]
checkArrOut:[]
checkArr: function (e) {
this.data.checkArr[e.target.dataset.id].check = !this.data.checkArr[e.target.dataset.id].check;
this.data.checkArrOut = []
for (let i = 0; i < this.data.checkArr.length; i++) {
if (this.data.checkArr[i].check == true) {
this.data.checkArrOut.push(this.data.checkArr[i].id)
}
}
this.setData(this.data)
console.log(this.data.checkArrOut)
},
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5c4e6d68a127240e947ce8c8fde52cda.png)
this.data.checkArrOut.push(this.data.checkArr[i].id)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/be5d2de1eb5c51cc44885b118733f608.png)
this.data.checkArrOut[i] = this.data.checkArr[i].id
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b91db10e3eeaa164fd4d1ad92016d63b.png)