根据选中的输入,我的函数付款应使用cost.innerHTML显示工资。
但我有问题。我的块“else if”不工作。
<div class="form__propertyInputs">
<span>qwerty</span> <input type="radio" name="propInput" id="property" checked>
<span>Nonqwerty</span> <input type="radio" name="propInput" id="noneProperty">
</div>
<div class="form__ownershipInputs hide">
<span>physical</span><input type="radio" name="ownerShipInput" id="physical">
<span>judical</span><input type="radio" name="ownerShipInput" id="judical">
</div>
<div class="form__debt" id="debtBlock">
<span>Debt:</span>
<input type="text" id="debt">
</div>
<div class="form__result">
<span>Sum:</span>
<div class="form__result-input"></div>
</div>
const debtBlock = document.querySelector('#debtBlock')
const debt = document.querySelector('#debt')
const ownershipInputs = document.querySelector('.form__ownershipInputs')
const property = document.querySelector('#property')
const noneProperty = document.querySelector('#noneProperty')
const cost = document.querySelector('.form__result-input')
const physical = document.querySelector('#physical')
const judical = document.querySelector('#judical')
let minSalary = 6700
noneProperty.addEventListener('change', toggleData)
property.addEventListener('change', toggleData)
debt.addEventListener('input', payment)
function toggleData() {
ownershipInputs.classList.toggle('hide')
debtBlock.classList.toggle('hide')
cost.innerHTML = ""
debt.value = ""
}
function payment() {
if (property.checked) {
if ((debt.value * 0.02) <= (minSalary * 10)) {
cost.innerHTML = (debt.value * 0.02).toFixed(2) + " грн"
} else if ((debt.value * 0.02) > (minSalary * 10)) {
cost.innerHTML = (minSalary * 10) + " грн"
}
} else if (noneProperty.checked) {
if (physical.checked) {
cost.innerHTML = minSalary + " грн"
} else if (judical.checked) {
cost.innerHTML = minSalary * 2 + " грн"
}
}
}
调试器没有帮助。给我建议如何处理这个问题。