Created
June 11, 2016 05:51
-
-
Save Restoration/6c94765173c5c06b5aa32839589c867f to your computer and use it in GitHub Desktop.
セレクトボックスの値を取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <select name="select" id="select"> | |
| <option value="1">Value1</option> | |
| <option value="2">Value2</option> | |
| <option value="3">Value3</option> | |
| </select> | |
| <script type="text/javascript"> | |
| //JavaScriptを使って取得する | |
| var selects = document.getElementById('select'); | |
| var option = document.getElementById('select').options; | |
| var value = option[selects.selectedIndex].text; | |
| //value値で取得するなら | |
| //var value = option[selects.selectedIndex].value; | |
| document.write(value); | |
| //jQueryを使って取得する | |
| jQuery(function($){ | |
| $('#select option:selected').text(); | |
| $('#select').children(':selected').text(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment