How to get value of selected radio button?

前端 未结 28 2875
温柔的废话
温柔的废话 2020-11-22 03:51

I want to get the selected value from a group of radio buttons.

Here\'s my HTML:

28条回答
  •  星月不相逢
    2020-11-22 04:34

    You can get the value by using the checked property.

    var rates = document.getElementsByName('rate');
    var rate_value;
    for(var i = 0; i < rates.length; i++){
        if(rates[i].checked){
            rate_value = rates[i].value;
        }
    }
    

提交回复
热议问题