jQuery getting text value for a select list

I have a list like this:

<select name="select_list_name" id="list_id">
    <option value="">Select Option</option>
    <option value="value1">Option 1</option>
    <option value="value2">Option 2</option>
    ...
    ...
</select>

I am trying to get the text value of the currently selected option in a select list. I looked at this thread: jQuery get specific option tag text and tried this:

$("#list_id option:selected").text()

But this only gets me the first options text ( "Select Option" ) regardless of which option has been selected.

I tried another way:

$("[name=select_list_name] option:selected").text()

That gets me the first option's text concatenated with the selected options's text ( "Select OptionOption 2" if I select Option 2).

Any idea on why?


$('#list_id :selected').text(); should give you the selected option's text.

Something else in your code must be wrong -- this piece of code really works


这项工作,100%,你有多个id'list_id'?

$('#list_id :selected').text();
链接地址: http://www.djcxy.com/p/83076.html

上一篇: 获取当前文本<select>

下一篇: jQuery获取选择列表的文本值