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

前端 未结 8 648
执笔经年
执笔经年 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:05

    var options = document.getElementsByName('myRadioButtons');
    for(i = 0; i < options.length; i++)
    {
        var opt = options[i];
        if(opt.type=="radio")
        {              
            if(opt.checked)
            {
            }                  
        }
    }
    

提交回复
热议问题