Home >Web Front-end >JS Tutorial >JavaScript uses this variable to quickly find out how the user selected the radio button_javascript tips

JavaScript uses this variable to quickly find out how the user selected the radio button_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:08:111579browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn