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

前端 未结 30 1734
南方客
南方客 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:19
    $('#id').find('option:selected').text();
    
    0 讨论(0)
  • 2020-11-21 16:20

    For the text of the selected item, use:

    $('select[name="thegivenname"] option:selected').text();
    

    For the value of the selected item, use:

    $('select[name="thegivenname"] option:selected').val();
    
    0 讨论(0)
  • 2020-11-21 16:20

    For getting selected value use

    $('#dropDownId').val();
    

    and for getting selected item text use this line:

    $("#dropDownId option:selected").text();
    
    0 讨论(0)
  • 2020-11-21 16:20

    Select Text and selected value on dropdown/select change event in jQuery

    $("#yourdropdownid").change(function() {
        console.log($("option:selected", this).text()); //text
        console.log($(this).val()); //value
    })
    
    0 讨论(0)
  • 2020-11-21 16:21

    Try this:

    $("#myselect :selected").text();
    

    For an ASP.NET dropdown you can use the following selector:

    $("[id*='MyDropDownId'] :selected")
    
    0 讨论(0)
  • 2020-11-21 16:22
    $("#yourdropdownid option:selected").text();
    
    0 讨论(0)
提交回复
热议问题