In JavaScript, how can I get all radio buttons in the page with a given name?

前端 未结 8 646
执笔经年
执笔经年 2020-12-03 11:14

Like the title says, what\'s the best way in JavaScript to get all radio buttons on a page with a given name? Ultimately I will use this to determine which specific radio b

8条回答
  •  半阙折子戏
    2020-12-03 12:07

    getElementsByName didn't work for me. I did this:

        var radios = document.getElementsByTagName('input');
        for (i = 0; i < radios.length; i++) {
            if (radios[i].type == 'radio' && radios[i].checked) {
                nbchecked++;
            }
        }
    

提交回复
热议问题