简体   繁体   English

禁用 div 并仅在选择单选按钮选项时启用

[英]Disable div and only enable when radio button option is chosen

How can I disable a div and activate it only after choosing a radio button option?如何仅在选择单选按钮选项后禁用 div 并激活它?

I can hide with hidden and show div when an option is selected, but hidden is not the desired property. I can hide with hidden and show div when an option is selected, but hidden is not the desired property.

Does anyone know a possible solution?有谁知道可能的解决方案?

<div class="col-s" [hidden]="show">

onValueChanged(c){
    if(c!=null){
      this.id= c.value.ID;
      this.show=false;
    }

  }

You could do it with *ngIf="show" .你可以用*ngIf="show"

<div class="col-s" *ngIf="show">

onValueChanged(c) {
  if(c! = null) {
    this.id = c.value.ID;
    this.show = false;
  }
}

You can set the pointer-events: none to prevent clicking.您可以设置pointer-events: none以防止单击。

component html组件 html

<div class="col-s" [ngStyle]="{'pointer-events': !show ? 'none' : 'initial' }">
  this button is only clickable if you choose -> show
  <button>click</button>
</div>

<label for="showtrue">show</label>
<input id="showtrue" type="radio" name="show" [value]="true" [(ngModel)]="show">

<br />

<label for="showfalse">dont't show (not clickable)</label>
<input id="showfalse" type="radio" name="show" [value]="false" [(ngModel)]="show">

component ts组件 ts

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  // if you want initial false, change it here
  show = true; // initial true (div is clickable)
}

if show is true, you can click.如果show为真,您可以点击。 If it is false, you can't.如果它是假的,你不能。


edit: here is an example how it works: https://ng-run.com/edit/Kzn3ChvHWUD4Jxn1cc2r编辑:这是一个例子,它是如何工作的: https://ng-run.com/edit/Kzn3ChvHWUD4Jxn1cc2r

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM