我正在尝试禁用该按钮,但 Typescript 代码不起作用!当我选择第一个和第二个复选框,但取消选择第一个复选框时,该按钮会自动禁用。 示例 示例2
<div class="satisfaction-survey-answers">
<h2>
Cuéntanos qué te agradó del proceso que acabas de realizar
</h2>
<div class="form-check">
<ul class="inner-panel">
<li>
<label class="inner-panel__checkbox">
Item número 1
<input id="toggle" type="checkbox" (change)="changeEvent($event)">
<span class="custom-check"></span>
</label>
</li>
<li>
<label class="inner-panel__checkbox">
Item número 2
<input type="checkbox" (change)="changeEvent($event)">
<span class="custom-check"></span>
</label>
</li>
<li>
<label class="inner-panel__checkbox">
Item número 3
<input type="checkbox" (change)="changeEvent($event)">
<span class="custom-check"></span>
</label>
</li>
</ul>
</div>
</div>
<div>
<app-button id="sendNewSms" [classButton]="'send-satisfaction-survey-button'" [typeButton]="'button'"
[labelButton]="'Enviar'" [isDisabled]="toggleBool">
</app-button>
</div>
toggleBool: boolean = true;
changeEvent(event) {
if (event.target.checked) {
this.toggleBool = false;
}
else {
this.toggleBool = true;
}
}
我编写了基于复选框禁用和更改网站部分内容的代码,但事实并非如此。我一开始做的时候觉得很困惑,但后来我明白了。 (当然放在html标签内)
<button id="abutton" onclick="// some code">A Button</button>
<input onclick="disableButton()" type="checkbox" id="checkbox">
<script>
function disableButton() {
if (document.getElementById('checkbox').checked == false) {
document.getElementById('abutton').disabled = true
} else if (document.getElementById('checkbox').checked == true) {
document.getElementById('abutton').disabled = false
}
}
</script>