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
Release: 2016-05-16 16:08:11
Original
1583 people have browsed it

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
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template