Home > Article > Web Front-end > A simple example of using js code to change the selected state of a radio button_javascript skills
Today there was a sudden need to use js code to change the selected state of the radio button. At that time, I didn’t even think about it.
function gel(id) {
return document.getElementById(id);
}
Because we set checked="checked" in the radio tag; so we subconsciously assigned the value of gel("radionv").style.checked to "checked", and then checked online
It turns out that to select the radio button in the js code, you need to assign the value of checked to true.
Continue to change to:
Isn’t it the style attribute? ? ? ?
Click gel("radionan") directly to see the checked attribute.
That’s right! ! ! ! !
That’s it! ! ! ! ! ! ! ! ! ! ! !