[英]How do you get the currently selected <option> in a <select> via JavaScript?
如何通过JavaScript获取当前选择的<select>
元素的<option>
?
This will do it for you: 这将为您做到:
var yourSelect = document.getElementById( "your-select-id" );
alert( yourSelect.options[ yourSelect.selectedIndex ].value )
The .selectedIndex
of the select
object has an index; select
对象的.selectedIndex
有一个索引; you can use that to index into the .options
array. 您可以使用它来索引
.options
数组。
var payeeCountry = document.getElementById( "payeeCountry" );
alert( payeeCountry.options[ yourSelect.selectedIndex ].value );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.