在 jQuery 中获取 SELECT 的值和文本

<! -- 自动插入的文本结束 --&gt;

对于 SELECT 框,如何在 jQuery 中获取选中项的值和文本?

例如

<option value="value">text</option>
解决办法

<select id="ddlViewBy">
    text
评论(1)
$('select').val()  // Get's the value

$('select option:selected').val() ; // Get's the value

$('select').find('option:selected').val() ; // Get's the value

$('select option:selected').text()  // Gets you the text of the selected option

[检查 FIDDLE][1]。

评论(0)

标签:)

HTML


<select id="my-select">
This is text 1
This is text 2
This is text 3
评论(0)