How do you get the currently selected

前端 未结 4 482
自闭症患者
自闭症患者 2020-12-04 19:00

How do you get the currently selected of a

提交评论

  • 2020-12-04 19:44
    var payeeCountry = document.getElementById( "payeeCountry" );
    alert( payeeCountry.options[ yourSelect.selectedIndex ].value );
    
    0 讨论(0)
  • 2020-12-04 19:47

    The .selectedIndex of the select object has an index; you can use that to index into the .options array.

    0 讨论(0)
  • 2020-12-04 19:48

    This will do it for you:

    var yourSelect = document.getElementById( "your-select-id" );
    alert( yourSelect.options[ yourSelect.selectedIndex ].value )
    
    0 讨论(0)
  • 提交回复
    热议问题