开发者

Getting selected text of a select listbox using JQuery when I already have the select object in hand

开发者 https://www.devze.com 2023-04-02 01:38 出处:网络
Here is an easy one, a true newbie question: I know that it\'s possible to get the text of the select开发者_JS百科ion option like this

Here is an easy one, a true newbie question:

I know that it's possible to get the text of the select开发者_JS百科ion option like this

$('#selectBoxId option:selected').val(); 

But what if I already have the select object in my hand?

e.g.

var select = $('#selectBoxId');

What comes next? this is the right way?

select.find('option:selected').val();


Just select.val(); is enough. It will give you the selected value.

Working demo

If you want the selected option text then your need to do

select.find('option:selected').text();

Or

select.find('option:selected').html();
0

精彩评论

暂无评论...
验证码 换一张
取 消