如何使用jQuery获得下拉框的选定值? 我试着用

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

and

var value = $('select#dropDownId option:selected').val();

但两者都返回空字符串。


当前回答

对于正常页面加载下拉列表

  $("#dropDownId").on('change',function(){
     var value=$(this).val();
     alert(value);
  });

确保保持id的唯一性

  $(document).on('change','#dropDownId',function(){
    var value=$(this).val();
    alert(value)
  });

其他回答

function fundrp(){ var text_value = $("#drpboxid option:selected").text(); console.log(text_value); var val_text = $("#drpboxid option:selected").val(); console.log(val_text); var value_text = $("#drpboxid option:selected").attr("value") ; console.log(value_text); var get_att_value = $("#drpboxid option:selected").attr("id") console.log(get_att_value); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> <select id="drpboxid"> <option id="1_one" value="one">one</option> <option id="2_two" value="two">two</option> <option id="3_three" value="three">three</option> </select> <button id="btndrp" onclick="fundrp()">Tracking Report1234</button>

我知道这是旧的,但我想我更新了一个更最新的答案

$( document ).on( 'change', '#combo', function () {
var prepMin= $("#combo option:selected").val();
 alert(prepMin);
});

我希望这对你们有帮助

$("#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>

你可以使用以下任何一种:

$(document).on('change', 'select#dropDownId', function(){

            var value = $('select#dropDownId option:selected').text();

            //OR

            var value = $(this).val();

});
$("#selector <b>></b> option:selected").val()

Or

$("#selector <b>></b> option:selected").text()

以上代码对我来说工作得很好