Javascript 检查正确答案后,禁用测验中的其他单选按钮

Javascript 检查正确答案后,禁用测验中的其他单选按钮,javascript,html,radio-button,Javascript,Html,Radio Button,我使用以下代码确定选中单选按钮的值是否正确,然后禁用或隐藏组中的所有其他单选按钮。这个简单的设置是我为客户准备的测验的一部分 <input type="radio" name="form[question-one]" value="f" id="question-one0" class="rsform-radio"> <label for="question-one0&

我使用以下代码确定选中单选按钮的值是否正确,然后禁用或隐藏组中的所有其他单选按钮。这个简单的设置是我为客户准备的测验的一部分

<input type="radio" name="form[question-one]" value="f" id="question-one0" class="rsform-radio">
<label for="question-one0">Sight</label>

<input type="radio" name="form[question-one]" value="f" id="question-one1" class="rsform-radio">
<label for="question-one1">Smell</label>

<input type="radio" name="form[question-one]" value="t" id="question-one2" class="rsform-radio">
<label for="question-one2">Hearing</label>

<input type="radio" name="form[question-one]" value="f" id="question-one3" class="rsform-radio">
<label for="question-one3">Taste</label>

let radios = document.getElementsByName('form[question-one]');
radios.forEach(radio => {
    radio.addEventListener('change', () => {
        for (let i = 0; i < radios.length; i++) {
            let radiosValue = radios[i];
            if (radiosValue.checked) {
                // The correct answer is marked by the 't' value
                if (radiosValue.value == 't') {
                    // Disable or hide all radio buttons that contain the value of 'f' when checked
                } else {
                    // Incorrect answers are marked with a 'f' value
                }
            }
        }
    });
});

景象
气味
听力
品味
let radios=document.getElementsByName('形式[问题一]);
收音机。forEach(收音机=>{
radio.addEventListener('change',()=>{
对于(设i=0;i
我不知道这是否是最好的解决方案。但它解决了您的问题。请将此添加到您的
if
语句中

if (radiosValue.value == 't') {
    radios.forEach((link)=>{
        if(link.value=='f'){
            link.disabled = true;
        }
    })
}