Javascript 即使选择了一个值,下拉列表仍处于禁用状态
有两个下拉按钮d1和d2。d2已禁用。从“d1”中选择值后,“d2”仍处于禁用状态Javascript 即使选择了一个值,下拉列表仍处于禁用状态,javascript,angular,disabled-input,Javascript,Angular,Disabled Input,有两个下拉按钮d1和d2。d2已禁用。从“d1”中选择值后,“d2”仍处于禁用状态 <div class="card-container"> <label>Country</label> <select placeholder="Country" [(ngModel)]="selectedCountry" (change)="changeCountry(
<div class="card-container">
<label>Country</label>
<select placeholder="Country" [(ngModel)]="selectedCountry" (change)="changeCountry($event)" >
<option>--Choose Country--</option>
<option *ngFor="let country of Countries" >{{country.name}}</option>
</select>
</div>
<div class="card-container">
<label>State</label>
<select placeholder="State" (change)="changeState($event)"
[disabled]="selectedCountry">
<option>--Choose State--</option>
<option *ngFor="let state of states">{{state.name}}</option>
</select>
</div>
国家
--选择国家--
{{country.name}
陈述
--选择州--
{{state.name}
在使用[disabled]=“selectedCountry”时,d2被禁用,但如果[disabled]=“!selectedCountry”,则d2未被禁用
我想使d2仅在选择d1时才可选择。[disabled]=“selectedCountry”
表示如果您对selectedCountry
有一些值,则它将为true
,这意味着它被禁用。所以情况应该是相反的
[disabled]="!selectedCountry"
如果选择的国家/地区没有任何值,将使其禁用
<div class="card-container">
<label>Country</label>
<select placeholder="Country" [(ngModel)]="selectedCountry" (change)="changeCountry($event)" >
<option>--Choose Country--</option>
<option *ngFor="let country of Countries" >{{country.name}}</option>
</select>
</div>
<div class="card-container">
<label>State</label>
<select placeholder="State" (change)="changeState($event)" [disabled]="!selectedCountry">
<option>--Choose State--</option>
<option *ngFor="let state of states">{{state.name}}</option>
</select>
</div>
国家
--选择国家--
{{country.name}
陈述
--选择州--
{{state.name}
另外,请确保selectedCountry
的初始值为selectedCountry='[disabled]=“selectedCountry”
表示如果您对selectedCountry
有一些值,则该值将为true
,这表示其已禁用。所以情况应该是相反的
[disabled]="!selectedCountry"
如果选择的国家/地区没有任何值,将使其禁用
<div class="card-container">
<label>Country</label>
<select placeholder="Country" [(ngModel)]="selectedCountry" (change)="changeCountry($event)" >
<option>--Choose Country--</option>
<option *ngFor="let country of Countries" >{{country.name}}</option>
</select>
</div>
<div class="card-container">
<label>State</label>
<select placeholder="State" (change)="changeState($event)" [disabled]="!selectedCountry">
<option>--Choose State--</option>
<option *ngFor="let state of states">{{state.name}}</option>
</select>
</div>
国家
--选择国家--
{{country.name}
陈述
--选择州--
{{state.name}
还要确保selectedCountry
的初始值为selectedCountry='
[disabled]=“!selectedCountry”
是您需要的[disabled]=“!selectedCountry”