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

前端 未结 30 1749
南方客
南方客 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:30

    Try:

    $var = jQuery("#dropdownid option:selected").val();
       alert ($var);
    

    Or to get the text of the option, use text():

    $var = jQuery("#dropdownid option:selected").text();
       alert ($var);
    

    More Info:

    • http://api.jquery.com/val/
    • http://api.jquery.com/text/

提交回复
热议问题