最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get the value of select jquery - Stack Overflow

programmeradmin1浏览0评论
<select id="my-select">
<option value="1">This is one</option>
<option value="2" selected>This is two</option>
...
</select>

Is there a way to get the text value of the selected option?

$('#my-select').val();

gives me 2, i want to get This is Two instead.

How?

<select id="my-select">
<option value="1">This is one</option>
<option value="2" selected>This is two</option>
...
</select>

Is there a way to get the text value of the selected option?

$('#my-select').val();

gives me 2, i want to get This is Two instead.

How?

Share Improve this question asked Jan 19, 2011 at 3:32 MarvzzMarvzz 1,5653 gold badges15 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

What you want is

  1. Get the selector for finding the selected option in the select box
  2. Use .text() on the selector.

    $('#my-select option:selected').text();
    

See a working demo

发布评论

评论列表(0)

  1. 暂无评论