Home >Web Front-end >JS Tutorial >JavaScript uses this variable to quickly find out how the user selected the radio button_javascript tips
The example in this article describes how JavaScript can quickly find out the user's selected radio button through this variable. Share it with everyone for your reference. The specific analysis is as follows:
The following JS code uses this variable combined with the onchange event of the radio button to quickly find out which radio button the user selected
<script> function favAnimal(button) { alert('You like '+button.value+'s.'); } </script> <input type="radio" name="marsupial" value="kangaroo" onchange="favAnimal(this)">Kangaroo <br /><input type="radio" name="marsupial" value="Opossum" onchange="favAnimal(this)">Opossum <br /><input type="radio" name="marsupial" value="Tasmanian Tiger" onchange="favAnimal(this)">Tasmanian Tiger
I hope this article will be helpful to everyone’s JavaScript programming design.