微信小程序实现多选框全选与取消全选功能示例
更新时间:2019年05月14日 10:44:44 作者:清风思月
这篇文章主要介绍了微信小程序实现多选框全选与取消全选功能,结合实例形式分析了微信小程序多选框功能实现、布局显示及全选、取消全选相关操作技巧,需要的朋友可以参考下
本文实例讲述了微信小程序实现多选框全选与取消全选功能。分享给大家供大家参考,具体如下:
js部分:
page({
data: { select_all:false,
listData: [{code: "111",text: "text1",typ: "type1",},
{code: "021",text: "text2",typ: "type2",},
{code: "111",text: "text1",typ: "type3",}]}
selectall: function() {//全选与反全选
var that = this;
for (let i = 0; i < that.data.listData.length; i++) {
that.data.listData[i].checked = (!that.data.select_all)}
that.setData({
listData: that.data.listData,
select_all: (!that.data.select_all)
})}
})
wxml部分:
<view class="scroll">
<scroll-view scroll-x="true">
<checkbox-group class="table" >
<view class="tr">
<view class="th">
<checkbox value="all" bindtap="selectall" />全选
</view>
<view class="th">运号</view>
<view class="th">V号</view>
<view class="th">运商</view>
<view class="th">返单</view>
<view class="th">日期</view>
</view>
<view class="tr" wx:for="{{listData}}" wx:key="">
<view class="td">
<checkbox value="{{item.code}}" checked="{{item.checked}}" />
</view>
<view class="td" value="{{item.text}}">{{item.code}}</view>
<view class="td" value="{{item.text}}">{{item.text}}</view>
<view class="td" value="{{item.typ}}">{{item.typ}}</view>
<view class="td" value="{{item.typ}}">{{item.typ}}</view>
<view class="td" value="{{item.typ}}">{{item.typ}}</view>
</view>
</checkbox-group>
</scroll-view>
</view>
</view>
wxss部分:
.table{
background-color: #fff;
border:1px solid #dadada;
width:1200rpx;
margin-left:0rpx;
}
.tr{
background-color: #dadada;
white-space: nowrap;
width:100%;
display: flex;
text-align: center;
justify-content: center;
}
.th{
background-color: #fff999;
text-align: center;
justify-content: center;
width: 100%;
border-bottom: 1px solid #dadada;
border-right: 1px solid #dadada;
}
.td{
background-color: #fff;
text-align: center;
justify-content: center;
width: 100%;
border-bottom: 1px solid #dadada;
border-right: 1px solid #dadada;
}
效果图:

希望本文所述对大家微信小程序开发有所帮助。
相关文章
JavaScript Date对象详解及时间戳和时间的相互转换问题
这篇文章主要介绍了JavaScript Date对象详解及时间戳和时间的相互转换问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧2024-01-01
使用Performance Observer实现网页性能优化的示例详解
在当今的网页开发中,性能监控已经成为确保用户体验的一个关键部分,本文将深入探讨一个强大的性能监控工具PerformanceObserver,看看如何使用它提升网站性能吧2025-03-03


最新评论