How do you get the currently selected <option>
of a <select>
element via JavaScript?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
Using the
selectedOptions
property:It works in all browsers except Internet Explorer.
The
.selectedIndex
of theselect
object has an index; you can use that to index into the.options
array.This will do it for you: