前端单选框勾叉选项

在实习工作中遇到的一个需求:
检查事项有很多项内容,需要对检查内容进行是否达标的判断,用选择勾或者叉来实现,每一项中点了勾就不能点叉,点了叉就不能点勾,点了叉/勾可以取消。

在这里插入图片描述

前端框架用的是Angular。

.html:

<div style="float: right;" [ngClass]="{radio2: flag2List[i]}" (click)="choose2(i)"><Icon [type]="'cross-circle'"></Icon></div>
<div style="margin-right: 10px;float: right;" [ngClass]="{radio1: flagList[i]}" (click)="choose1(i)"><Icon [type]="'check-circle-o'"></Icon></div>

.css:

:host ::ng-deep{
	.am-icon-md {
        color: #777;
    }
    .radio1 .am-icon-md {
        color: green;
    }
    .radio2 .am-icon-md {
        color: red;
    }
}

.ts:

flagList = [];  // 勾
flag2List = []; // 叉
checkItems = {}; //用来存储每一行的选择勾叉情况

// 叉
n = [];
  choose2(i) {
    this.flag2List[i] = !this.flag2List[i];
    this.flagList[i] = false;
    this.checkItems[i] = false;
    
    if(this.checkItems[i] != true && this.n[i] == true) {
      this.checkItems[i] = null;
      this.n[i] = false;
    }
    this.n[i]=true;
  }
  
  // 勾
  m = [];
  choose1(i) {
    this.flagList[i] = !this.flagList[i];
    this.flag2List[i]  = false;
    this.checkItems[i] = true;

    if(this.checkItems[i] != false && this.m[i] == true) {
      this.checkItems[i] = null;
      this.m[i] = false;
    }
    this.m[i]=true;
  }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值