How does jQuery operate the text and value values in the select drop-down box?

Source: Internet
Author: User

1. jquery obtains the text value of the selected select statement.

Var checkText = $ ("# slc1"). find ("option: selected"). text ();

2. jquery obtains the value of the selected select statement.

Var checkValue = $ ("# slc1"). val ();

3. jquery obtains the index value of the selected select statement.

Var index = $ ("# slc1"). get (0). selectedIndex;

4. jquery sets the item with an index value of 1 as the currently selected item.

$ ("# Slc1"). get (0). selectedIndex = 1;

5. jquery sets the item of value 2 as the currently selected item.

$ ("# Slc1"). val (2 );

6. jquery sets the text value to "qingteng Garden" as the selected item.

$ ("# Slc1 option [text = 'qingyuan W']"). attr ("selected", true );

7. append an option to the specified select drop-down box (append to the end)

$ ("# Slc2"). append ("" + I + "");

8. insert an option into the select drop-down box (insert to the first position)

$ ("# Slc2"). prepend ("select ");

9. jquery deletes the last option in the select drop-down box.

$ ("# Slc2 option: last"). remove ();

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.