加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

微信小程序复选框实现 多选一功能

发布时间:2020-12-14 19:01:23 所属栏目:资源 来源:网络整理
导读:功能实现界面 data: { checkboxItems: [ { name: '全天(1-8节)',value: 'allday' },{ name: '上午(1-4节)',value: 'am' '下午(5-8节)',value: 'pm' '晚上(晚自习)',value: 'night' ? ? 想要实现的功能 ? 四个复选框中只能选一个,且选中另一个会取消其余选中

功能实现界面

data: {
    checkboxItems: [
      { name: '全天(1-8节)',value: 'allday' },{ name: '上午(1-4节)',value: 'am''晚上(晚自习)',value: 'night'
checkboxChange: function (e) {
    var that = this;
    let checkboxValues=null;
    let checkboxItems = this.data.checkboxItems,values = e.detail.value
    for (var i = 0,lenI = checkboxItems.length; i < lenI; ++i) {
      if(checkboxItems[i].value==values[values.length-1]){
        checkboxItems[i].checked=true;
        checkboxValues = checkboxItems[i].value;
      }
      else{
        checkboxItems[i].checked = false;
      }
    }
    console.log(checkboxValues)
    that.setData({ checkboxItems,checkboxValues })
  }

?

?

前端代码

?

<view class="weui-cells weui-cells_after-title">
      checkbox-group ="weui-flex" bindchange="checkboxChange">
        label ="weui-cell weui-check__label weui-flex__item" wx:for="{{checkboxItems}}" wx:key="value">
          checkbox ="weui-check" value="{{item.value}}" checked="{{item.checked}}" />
          ="weui-cell__hd weui-check__hd_in-checkbox">
            icon ="weui-icon-checkbox_circle" type="circle" size="23" wx:if="{{!item.checked}}"></icon="weui-icon-checkbox_success"="success"="{{item.checked}}"</view="weui-cell__bd">{{item.name}}labelcheckbox-group>
    >

?

?

?

对应的CSS样式是

WeUI

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读