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

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

and

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

但两者都返回空字符串。


当前回答

HTML:

<select class="form-control" id="SecondSelect">
       <option>5<option>
       <option>10<option>
       <option>20<option>
       <option>30<option>
</select>

JavaScript:

var value = $('#SecondSelect')[0].value;

其他回答

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

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

我希望这对你们有帮助

你需要这样放。

$('[id$=dropDownId] option:selected').val();
$("#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>

使用下面的代码行,我们可以得到下拉列表值。这将工作

var getValue =文档。

使用下面的方法在页面加载中获取所选值:

$(document).ready(function () {
$('#ddlid').on('change', function () {
                var value = $('#ddlid :selected').text();
                alert(value);`
            });
});