Get selected value of a dropdown's item using jQuery

后端 未结 30 1413
广开言路
广开言路 2020-11-22 06:48

How can I get the selected value of a dropdown box using jQuery?
I tried using

var value = $(\'#dropDownId\').val();

and



        
相关标签:
30条回答
  • 2020-11-22 06:57

    Use the method below to get the selected value on page load:

    $(document).ready(function () {
    $('#ddlid').on('change', function () {
                    var value = $('#ddlid :selected').text();
                    alert(value);`
                });
    });
    
    0 讨论(0)
  • 2020-11-22 06:57
    $("#dropDownId").val('2');
    var SelectedValue= $("#dropDownId option:selected").text();
    $(".ParentClass .select-value").html(SelectedValue);
    
    
    <p class="inline-large-label button-height ParentClass" >
         <label for="large-label-2" class="label">Country <span style="color: Red;">*</span><small></small></label>
         <asp:DropDownList runat="server" ID="dropDownId " CssClass="select" Width="200px">          
        </asp:DropDownList>
    </p>
    
    0 讨论(0)
  • 2020-11-22 06:58

    For selected text use:

    value: $('#dropDownId :selected').text();
    

    For selected value use:

    value: $('#dropDownId').val();
    
    0 讨论(0)
  • 2020-11-22 06:58
    $("select[id$=dropDownId]").val()
    
    • try this
    0 讨论(0)
  • 2020-11-22 06:58

    You need to put like this.

    $('[id$=dropDownId] option:selected').val();
    
    0 讨论(0)
  • 2020-11-22 06:59

    use

    $('#dropDownId').find('option:selected').val()
    

    This should work :)

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