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

标签 javascript html angular

如何禁用 div 并仅在选择单选按钮选项后才激活它?

我可以使用hidden隐藏并在选择选项时显示div,但hidden不是所需的属性。

有人知道可能的解决方案吗?

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

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

  }

最佳答案

您可以设置pointer-events: none来防止点击。

组件 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">

组件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)
}

如果show为true,则可以点击。如果它是假的,你就不能。

<小时/>

编辑:以下是其工作原理的示例: https://ng-run.com/edit/Kzn3ChvHWUD4Jxn1cc2r

关于javascript - 禁用 div 并仅在选择单选按钮选项时启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58547004/

相关文章:

javascript - Angular 2,如何编写自定义 mousedown/touchstart 实现

javascript - 同步调用

javascript - Meteor - 简单的搜索问题

javascript - 有人知道为什么这些元素会出现在移动网站上吗?

html - 同一行上两个具有动态大小的框的CSS

angular - 任何人都经历过 angular2 加载速度慢的情况

javascript - 为什么不返回 DOM 元素边框宽度?

javascript - findOne Mongoose 查询无法正常工作

javascript - AngularJS 路由示例不起作用

javascript - 如何防止带有 Moment Js 的 Angular Material 6 DatePicker 转换不正确的格式?