根据下拉文本框中的选择值,将在Angular中启用或禁用

发布于 2025-02-07 18:43:12 字数 912 浏览 1 评论 0原文

我根据我编写代码,以一个下拉列表,由2个值IE启用,禁用。根据选择,应启用和禁用文本框。有人可以告诉我如何

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

@Component({
  selector: 'app-dropdown',
  templateUrl: './dropdown.component.html',
  styleUrls: ['./dropdown.component.css']
})
export class DropdownComponent implements OnInit {
  des = false

  constructor() { }
  
  onchange(){
  if (true) {
    this.des=false
    
  }
  else{
    this.des= true
  }
  }
  ngOnInit(): void {
  }

}
<select name="dropdown" id="this">select the correct value 
    (change)="onchange()"
    <option value="yes">yes</option>
    <option value="No">No</option>
</select>

<input type="text" [disabled]="!des">

采取选项的价值以及我可以在IF-ELSE部分中提供的条件

I write the code according to me for one dropdown consisting of 2 values i.e. Enabled, Disabled. As per the selection, the textbox should be enabled and disabled. can anybody tell me how to

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

@Component({
  selector: 'app-dropdown',
  templateUrl: './dropdown.component.html',
  styleUrls: ['./dropdown.component.css']
})
export class DropdownComponent implements OnInit {
  des = false

  constructor() { }
  
  onchange(){
  if (true) {
    this.des=false
    
  }
  else{
    this.des= true
  }
  }
  ngOnInit(): void {
  }

}
<select name="dropdown" id="this">select the correct value 
    (change)="onchange()"
    <option value="yes">yes</option>
    <option value="No">No</option>
</select>

<input type="text" [disabled]="!des">

take the value of options and what condition I can give in the if-else section

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红衣飘飘貌似仙 2025-02-14 18:43:12

在html文件

<select name="dropdown" (change)="onChange($event)">
  select the correct value
  <option value="No">No</option>
  <option value="yes">yes</option>
</select>

<input type="text" [disabled]="des">

  onChange(ev) {
    this.des = ev.target.value === 'yes'
  }

In HTML file add event as a parameter in your case:

<select name="dropdown" (change)="onChange($event)">
  select the correct value
  <option value="No">No</option>
  <option value="yes">yes</option>
</select>

<input type="text" [disabled]="des">

and in ts file add function

  onChange(ev) {
    this.des = ev.target.value === 'yes'
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文