Get the value of a dropdown in jQuery

后端 未结 10 2246
臣服心动
臣服心动 2020-11-29 02:46

I have a drop down that has an \'ID, Name\' Pair.

Example

Jon Miller
Jim Smith
Jen Morsin

Jon MIller has ID of 101
Jim Smith has ID of 10

相关标签:
10条回答
  • 2020-11-29 03:06

    $('#Crd').val() will give you the selected value of the drop down element. Use this to get the selected options text.

    $('#Crd option:selected').text();
    
    0 讨论(0)
  • 2020-11-29 03:09

    Pass the id and hold into a variable and pass the variable where ever you want.

    var temp = $('select[name=ID Name]').val();

    0 讨论(0)
  • 2020-11-29 03:21

    The best way is to use:

    $("#yourid option:selected").text();
    

    Depending on the requirement, you could also use this way:

    var v = $("#yourid").val();
    $("#yourid option[value="+v+"]").text()
    
    0 讨论(0)
  • 2020-11-29 03:21

    Another option:

    $("#<%=dropDownId.ClientID%>").children("option:selected").val();
    
    0 讨论(0)
提交回复
热议问题