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

前端 未结 30 1685
南方客
南方客 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:15
    var e = document.getElementById("dropDownId");
    var div = e.options[e.selectedIndex].text;
    
    0 讨论(0)
  • 2020-11-21 16:15

    If you want the result as a list, then use:

    x=[];
    $("#list_id").children(':selected').each(function(){x.push($(this).text());})
    
    0 讨论(0)
  • 2020-11-21 16:18
    $("#dropdownID").change(function(){
      alert($('option:selected', $(this)).text());
    });
    
    0 讨论(0)
  • 2020-11-21 16:18

    For those who are using SharePoint lists and don't want to use the long generated id, this will work:

    var e = $('select[title="IntenalFieldName"] option:selected').text();
    
    0 讨论(0)
  • 2020-11-21 16:19

    This works for me:

    $('#yourdropdownid').find('option:selected').text();
    

    jQuery version: 1.9.1

    0 讨论(0)
  • 2020-11-21 16:19
    $("select[id=yourDropdownid] option:selected").text()
    

    This works fine

    0 讨论(0)
提交回复
热议问题