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

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

and

var value = $('select#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>

其他回答

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

Or

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

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

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

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

确保保持id的唯一性

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

use

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

这应该工作:)

对于单个select dom元素,获取当前选择的值:

$('#dropDownId').val();

获取当前选定的文本:

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

您是否为选择元素提供了id?

<select id='dropDownId'> ...

你的第一句话应该有用!