如何通过JavaScript在<select>中获取当前选择的<option>?</select> </option>

时间:2010-07-21 16:42:43

标签: javascript html html-select

如何通过JavaScript获取{em>当前选中的<option>元素<{1}}?

4 个答案:

答案 0 :(得分:93)

这将为你做到:

var yourSelect = document.getElementById( "your-select-id" );
alert( yourSelect.options[ yourSelect.selectedIndex ].value )

答案 1 :(得分:18)

select对象的.selectedIndex有一个索引;您可以使用它来索引.options数组。

答案 2 :(得分:2)

var payeeCountry = document.getElementById( "payeeCountry" );
alert( payeeCountry.options[ yourSelect.selectedIndex ].value );

答案 3 :(得分:1)

使用selectedOptions属性:

var yourSelect = document.getElementById("your-select-id");
alert(yourSelect.selectedOptions[0].value);

除了Internet Explorer之外的所有浏览器中都有works