Pau*_*ite 55 html javascript html-select
如何通过JavaScript 获取当前选定<option>的<select>元素?
Pat*_*Pat 95
这将为您做到:
var yourSelect = document.getElementById( "your-select-id" );
alert( yourSelect.options[ yourSelect.selectedIndex ].value )
Run Code Online (Sandbox Code Playgroud)
小智 5
var payeeCountry = document.getElementById( "payeeCountry" );
alert( payeeCountry.options[ yourSelect.selectedIndex ].value );
Run Code Online (Sandbox Code Playgroud)
使用该selectedOptions属性:
var yourSelect = document.getElementById("your-select-id");
alert(yourSelect.selectedOptions[0].value);
Run Code Online (Sandbox Code Playgroud)
它适用于除 Internet Explorer 之外的所有浏览器。