开发者

You need to select at least one radio button / checkbox

What would be the JavaScript code to check if the user has select开发者_运维问答ed at least one radio button, knowing that the radio buttons all have the same "name" attribute?

Same question for checkboxes.

I do not use any fancy javascript frameworks such as JQuery and others ...


function IsARadioButtonChecked ( radiogroup ) {
    for (var i = 0; i < radiogroup.length; i++) {
        if (radiogroup[i].checked) {
            return true;
        }
    }
    return false;
}

if (IsARadioButtonChecked(document.forms.myForm.elements.myRadioGroupName)) {
    // …
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜