This article mainly introduces jquery's method of getting select selected values, and analyzes in detail jQuery's method of getting select selected option text values and value values based on examples, at the same time, we provide tips for using JavaScript to obtain select selected items. For more information, see the example in this article. We will share this with you for your reference. The details are as follows:
Misunderstanding:
Previously, I thought jquery would get the selected text value of option in select, which is written as follows:
The Code is as follows:
$ ("# S"). text (); // obtain the text value of all options
In fact, it should be like this:
The Code is as follows:
$ ("# S option: selected"). text (); // obtain the text value of the selected option
Obtain the selected value of option in select:
$ ("# S"). val (); $ ("# s option: selected"). val ();
Js gets the selected select value:
Var sel = document. getElementById ("select1"); var index = sel. selectedIndex; // select the index albumid = sel. options [index]. value; // value
I hope this article will help you with jQuery programming.