JavaScript 函数返回"非法返回语句"



我正在尝试找到哪些无线电输入,因此我可以将信息传递给我的main.js(electron)。

function checkType(){
    const types = document.getElementById('type').children;
        for (var i; i < types.length; i++){
            if (types[i].checked == true){
                return types[i].id;
            }
        }
}

它应该返回所选输入的ID,但我收到了非法返回错误。

这是我的div:

<div id="type">
    <label for="urgent">Urgent</label>
    <input type="radio" id="urgent" name="type">
    <br>
    <label for="request">Request</label>
    <input type="radio" id="request" name="type">
    <br>
    <label for="question">Question</label>
    <input type="radio" id="Question" name="type">
    <br>
</div
function checkType(){
    const types = document.getElementById('type').children;
    let selected;
        for (var i; i < types.length; i++){
            if (types[i].checked == true){
                selected = types[i].id
                break;
            }
        }
    return selected;
}

最新更新