Method Analysis for jquery to obtain the selected select value _ jquery

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.