Javascript 我可以用radio类型在单击输入字段时更改布尔值吗?
单击输入字段时,我如何分配标志Javascript 我可以用radio类型在单击输入字段时更改布尔值吗?,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,单击输入字段时,我如何分配标志true或false: 在我的.ts文件中: one:boolean=false; two:boolean=false; 在.html文件中 <div class="container"> <label>Yes <input type="radio" id="one"> </label> </div> <div
true
或false
:
在我的.ts
文件中:
one:boolean=false;
two:boolean=false;
在.html
文件中
<div class="container">
<label>Yes
<input type="radio" id="one">
</label>
</div>
<div class="container">
<label> No
<input type="radio" id="one">
</label>
</div>
对
不
用[(ngModel)]绑定您的单选按钮。
将解决您的问题
试试这个
对
不
试试这个
<p>
<input type="radio" value="one" name="gender" [(ngModel)]="result" (ngModelChange)="setValues()" > One
<input type="radio" value="two" name="gender" [(ngModel)]="result" (ngModelChange)="setValues()" > Two
</p>
这回答了你的问题吗?
one =true;
two=false;
result;
setValues(){
this.one =this.result === 'one' ? true :false;
this.two =this.result === 'two' ? true :false;
}