How to get the selected label from a html <select>?

前端 未结 3 2063
死守一世寂寞
死守一世寂寞 2020-12-09 02:10

HTML Javascript question

to get the selected value of a input-select I can use


                        
    
提交评论

  • 2020-12-09 02:29
    var el = document.getElementById('gender');
    var text = el.options[el.selectedIndex].innerHTML;
    
    0 讨论(0)
  • 2020-12-09 02:39

    This should work:

    var label = document.getElementById('gender')[document.getElementById('gender').selectedIndex].innerHTML;
    
    0 讨论(0)
  • 提交回复
    热议问题