How to set radio button status with JavaScript

前端 未结 8 1286
抹茶落季
抹茶落季 2020-12-04 21:11

What method would be best to use to selectively set a single or multiple radio button(s) to a desired setting with JavaScript?

8条回答
  •  一个人的身影
    2020-12-04 21:22

    /**
     * setCheckedValueOfRadioButtonGroup
     * @param {html input type=radio} vRadioObj 
     * @param {the radiobutton with this value will be checked} vValue 
     */
    function setCheckedValueOfRadioButtonGroup(vRadioObj, vValue) {
        var radios = document.getElementsByName(vRadioObj.name);
        for (var j = 0; j < radios.length; j++) {
            if (radios[j].value == vValue) {
                radios[j].checked = true;
                break;
            }
        }
    }
    

提交回复
热议问题