Get selected text from a drop-down list (select box) using jQuery

前端 未结 30 2188
南方客
南方客 2020-11-21 15:58

How can I get the selected text (not the selected value) from a drop-down list in jQuery?

30条回答
  •  野的像风
    2020-11-21 16:10

    Use this

    const select = document.getElementById("yourSelectId");
    
    const selectedIndex = select.selectedIndex;
    const selectedValue = select.value;
    const selectedText = select.options[selectedIndex].text;   
    

    Then you get your selected value and text inside selectedValue and selectedText.

提交回复
热议问题